You are here

protected function S3fsStreamWrapper::_open_read_stream in S3 File System 7

Same name and namespace in other branches
  1. 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::_open_read_stream()

Initialize the stream wrapper for a read only stream.

Parameters

array $params: A Command parameters array.

array $errors: Array to which encountered errors should be appended.

Return value

bool

1 call to S3fsStreamWrapper::_open_read_stream()
S3fsStreamWrapper::stream_open in ./S3fsStreamWrapper.inc
Support for fopen(), file_get_contents(), file_put_contents() etc.

File

./S3fsStreamWrapper.inc, line 1317
Drupal stream wrapper implementation for S3 File System.

Class

S3fsStreamWrapper
The stream wrapper class.

Code

protected function _open_read_stream($params, &$errors) {
  $this
    ->_debug("_open_read_stream({$params['Key']}) called.", TRUE);

  // Create the command and serialize the request.
  $request = $this
    ->_get_signed_request($this->s3
    ->getCommand('GetObject', $params));

  // Create a stream that uses the EntityBody object.
  $factory = $this
    ->_get_option('stream_factory');
  if (empty($factory)) {
    $factory = new Guzzle\Stream\PhpStreamRequestFactory();
  }
  $this->body = $factory
    ->fromRequest($request, array(), array(
    'stream_class' => 'Guzzle\\Http\\EntityBody',
  ));

  // Wrap the body in an S3fsSeekableCachingEntityBody, so that seeks can
  // go to not-yet-read sections of the file.
  if (class_exists('S3fsSeekableCachingEntityBody')) {
    $this->body = new S3fsSeekableCachingEntityBody($this->body);
  }
  return TRUE;
}