/**
  * @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
  * @param \WindowsAzure\Blob\Internal\IBlob                             $blobProxy
  * @param \WindowsAzure\Blob\Models\GetBlobResult                       $getBlobResult
  */
 public function it_should_read_file($blobProxyFactory, $blobProxy, $getBlobResult)
 {
     $getBlobResult->getContentStream()->shouldBeCalled()->willReturn(fopen('data://text/plain,some content', 'r'));
     $blobProxy->getBlob('containerName', 'filename')->shouldBeCalled()->willReturn($getBlobResult);
     $blobProxyFactory->create()->shouldBeCalled()->willReturn($blobProxy);
     $this->read('filename')->shouldReturn('some content');
 }
 /**
  * Creates GetBlobResult from getBlob call.
  * 
  * @param array  $headers  The HTTP response headers.
  * @param string $body     The response body.
  * @param array  $metadata The blob metadata.
  * 
  * @return GetBlobResult
  */
 public static function create($headers, $body, $metadata)
 {
     $result = new GetBlobResult();
     $result->setContentStream(Utilities::stringToStream($body));
     $result->setProperties(BlobProperties::create($headers));
     $result->setMetadata(is_null($metadata) ? array() : $metadata);
     return $result;
 }
 /**
  * @covers WindowsAzure\Blob\Models\GetBlobResult::setContentStream
  * @covers WindowsAzure\Blob\Models\GetBlobResult::getContentStream
  */
 public function testSetContentStream()
 {
     // Setup
     $expected = Utilities::stringToStream('0x8CAFB82EFF70C46');
     $result = new GetBlobResult();
     // Test
     $result->setContentStream($expected);
     // Assert
     $this->assertEquals($expected, $result->getContentStream());
 }
Exemple #4
0
 /**
  * Reads or downloads a blob from the system, including its metadata and 
  * properties.
  * 
  * @param string                $container name of the container
  * @param string                $blob      name of the blob
  * @param Models\GetBlobOptions $options   optional parameters
  * 
  * @return Models\GetBlobResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx
  */
 public function getBlob($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     $method = Resources::HTTP_GET;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = array(Resources::STATUS_OK, Resources::STATUS_PARTIAL_CONTENT);
     if (is_null($options)) {
         $options = new GetBlobOptions();
     }
     $getMD5 = $options->getComputeRangeMD5();
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->_addOptionalRangeHeader($headers, $options->getRangeStart(), $options->getRangeEnd());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $this->addOptionalHeader($headers, Resources::X_MS_RANGE_GET_CONTENT_MD5, $getMD5 ? 'true' : null);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $metadata = $this->getMetadataArray($response->getHeader());
     return GetBlobResult::create($response->getHeader(), $response->getBody(), $metadata);
 }