equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service |
16 * @package Zend_Service |
17 * @subpackage Amazon_S3 |
17 * @subpackage Amazon_S3 |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: Stream.php 22621 2010-07-18 00:35:48Z torio $ |
20 * @version $Id: Stream.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_Service_Amazon_S3 |
24 * @see Zend_Service_Amazon_S3 |
25 */ |
25 */ |
29 * Amazon S3 PHP stream wrapper |
29 * Amazon S3 PHP stream wrapper |
30 * |
30 * |
31 * @category Zend |
31 * @category Zend |
32 * @package Zend_Service |
32 * @package Zend_Service |
33 * @subpackage Amazon_S3 |
33 * @subpackage Amazon_S3 |
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 */ |
36 */ |
37 class Zend_Service_Amazon_S3_Stream |
37 class Zend_Service_Amazon_S3_Stream |
38 { |
38 { |
39 /** |
39 /** |
138 $this->_objectSize = 0; |
138 $this->_objectSize = 0; |
139 $this->_position = 0; |
139 $this->_position = 0; |
140 $this->_writeBuffer = true; |
140 $this->_writeBuffer = true; |
141 $this->_getS3Client($path); |
141 $this->_getS3Client($path); |
142 return true; |
142 return true; |
143 } |
143 } else { |
144 else { |
|
145 // Otherwise, just see if the file exists or not |
144 // Otherwise, just see if the file exists or not |
146 $info = $this->_getS3Client($path)->getInfo($name); |
145 $info = $this->_getS3Client($path)->getInfo($name); |
147 if ($info) { |
146 if ($info) { |
148 $this->_objectName = $name; |
147 $this->_objectName = $name; |
149 $this->_objectBuffer = null; |
148 $this->_objectBuffer = null; |
173 } |
172 } |
174 |
173 |
175 /** |
174 /** |
176 * Read from the stream |
175 * Read from the stream |
177 * |
176 * |
178 * http://bugs.php.net/21641 - stream_read() is always passed PHP's |
177 * http://bugs.php.net/21641 - stream_read() is always passed PHP's |
179 * internal read buffer size (8192) no matter what is passed as $count |
178 * internal read buffer size (8192) no matter what is passed as $count |
180 * parameter to fread(). |
179 * parameter to fread(). |
181 * |
180 * |
182 * @param integer $count |
181 * @param integer $count |
183 * @return string |
182 * @return string |
184 */ |
183 */ |
185 public function stream_read($count) |
184 public function stream_read($count) |
192 if ($count + $this->_position > $this->_objectSize) { |
191 if ($count + $this->_position > $this->_objectSize) { |
193 $count = $this->_objectSize - $this->_position; |
192 $count = $this->_objectSize - $this->_position; |
194 } |
193 } |
195 |
194 |
196 $range_start = $this->_position; |
195 $range_start = $this->_position; |
197 $range_end = $this->_position+$count; |
196 $range_end = $this->_position + $count - 1; |
198 |
197 |
199 // Only fetch more data from S3 if we haven't fetched any data yet (postion=0) |
198 // Only fetch more data from S3 if we haven't fetched any data yet (postion=0) |
200 // OR, the range end position is greater than the size of the current object |
199 // OR, the range end position plus 1 is greater than the size of the current |
201 // buffer AND if the range end position is less than or equal to the object's |
200 // object buffer |
202 // size returned by S3 |
201 if ($this->_objectBuffer === null || $range_end >= strlen($this->_objectBuffer)) { |
203 if (($this->_position == 0) || (($range_end > strlen($this->_objectBuffer)) && ($range_end <= $this->_objectSize))) { |
|
204 |
|
205 $headers = array( |
202 $headers = array( |
206 'Range' => "bytes=$range_start-$range_end" |
203 'Range' => "bytes=$range_start-$range_end" |
207 ); |
204 ); |
208 |
205 |
209 $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers); |
206 $response = $this->_s3->_makeRequest('GET', $this->_objectName, null, $headers); |