fopen s3 objects directly to work around unexplainable guzzle bug

For some reason when a text file started with a valid hex character ([0-9a-f]) it would eat the text untill the first newline
The new code does basically the same thing as guzzle/s3-sdk did only without wrapping everything in a guzzle stream

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2016-10-28 16:35:39 +02:00
parent eb21dc2bd3
commit 3ab160dd5a
No known key found for this signature in database
GPG Key ID: 425003AC385454C5
1 changed files with 21 additions and 30 deletions

View File

@ -21,11 +21,6 @@
namespace OC\Files\ObjectStore;
use Guzzle\Http\EntityBody;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Stream\PhpStreamRequestFactory;
use Icewind\Streams\CallbackWrapper;
use OCP\Files\ObjectStore\IObjectStore;
// TODO: proper composer
@ -48,20 +43,6 @@ class S3 implements IObjectStore {
return $this->id;
}
/**
* Serialize and sign a command, returning a request object
*
* @param CommandInterface $command Command to sign
*
* @return RequestInterface
*/
protected function getSignedRequest($command) {
$request = $command->prepare();
$request->dispatch('request.before_send', array('request' => $request));
return $request;
}
/**
* @param string $urn the unified resource name used to identify the object
* @return resource stream with the read data
@ -70,20 +51,30 @@ class S3 implements IObjectStore {
*/
function readObject($urn) {
// Create the command and serialize the request
$request = $this->getSignedRequest($this->getConnection()->getCommand('GetObject', [
$request = $this->getConnection()->getCommand('GetObject', [
'Bucket' => $this->bucket,
'Key' => $urn
]));
// Create a stream that uses the EntityBody object
$factory = new PhpStreamRequestFactory();
/** @var EntityBody $body */
$body = $factory->fromRequest($request, array(), array('stream_class' => 'Guzzle\Http\EntityBody'));
$stream = $body->getStream();
])->prepare();
// we need to keep the guzzle request in scope untill the stream is closed
return CallbackWrapper::wrap($stream, null, null, function () use ($body) {
$body->close();
});
$request->dispatch('request.before_send', array(
'request' => $request
));
$headers = $request->getHeaderLines();
$headers[] = 'Connection: close';
$opts = [
'http' => [
'method' => "GET",
'header' => $headers
],
'ssl' => [
'verify_peer' => true
]
];
$context = stream_context_create($opts);
return fopen($request->getUrl(), 'r', false, $context);
}
/**