Skip to content

Commit

Permalink
Make inputResource() find the buffer length when set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
tpyo committed Jun 13, 2013
1 parent a938ec8 commit 31646fe
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,25 @@ public static function inputFile($file, $md5sum = true)
* @param string $md5sum MD5 hash to send (optional)
* @return array | false
*/
public static function inputResource(&$resource, $bufferSize, $md5sum = '')
public static function inputResource(&$resource, $bufferSize = false, $md5sum = '')
{
if (!is_resource($resource) || $bufferSize < 0)
if (!is_resource($resource) || (int)$bufferSize < 0)
{
self::__triggerError('S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__);
return false;
}

// Try to figure out the bytesize
if ($bufferSize === false)
{
if (fseek($resource, 0, SEEK_END) < 0 || ($bufferSize = ftell($resource)) === false)
{
self::__triggerError('S3::inputResource(): Unable to obtain resource size', __FILE__, __LINE__);
return false;
}
fseek($resource, 0);
}

$input = array('size' => $bufferSize, 'md5sum' => $md5sum);
$input['fp'] =& $resource;
return $input;
Expand Down

0 comments on commit 31646fe

Please sign in to comment.