Beispiel #1
0
 /**
  * Read from the stream
  *
  * http://bugs.php.net/21641 - stream_read() is always passed PHP's
  * internal read buffer size (8192) no matter what is passed as $count
  * parameter to fread().
  *
  * @param  integer $count
  * @return string
  */
 public function stream_read($count)
 {
     if (!$this->_objectName) {
         return false;
     }
     // make sure that count doesn't exceed object size
     if ($count + $this->_position > $this->_objectSize) {
         $count = $this->_objectSize - $this->_position;
     }
     $range_start = $this->_position;
     $range_end = $this->_position + $count;
     // Only fetch more data from S3 if we haven't fetched any data yet (postion=0)
     // OR, the range end position is greater than the size of the current object
     // buffer AND if the range end position is less than or equal to the object's
     // size returned by S3
     if ($this->_position == 0 || $range_end > strlen($this->_objectBuffer) && $range_end <= $this->_objectSize) {
         $headers = array('Range' => "bytes={$range_start}-{$range_end}");
         $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers);
         if ($response->getStatusCode() == 206) {
             // 206 Partial Content
             $this->_objectBuffer .= $response->getBody();
         }
     }
     $data = substr($this->_objectBuffer, $this->_position, $count);
     $this->_position += strlen($data);
     return $data;
 }