public function testCanGetCommandForUploadPart()
 {
     $this->prepareTransfer(true);
     $part = UploadPart::fromArray(array('partNumber' => 1, 'checksum' => 'foo', 'contentHash' => 'bar', 'size' => 10, 'offset' => 5));
     $command = $this->callProtectedMethod($this->transfer, 'getCommandForPart', array($part, true));
     $this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $command);
     $this->assertEquals('foo', $command->get('checksum'));
 }
 public function testBasicOperations()
 {
     /** @var $part UploadPart */
     $part = UploadPart::fromArray(array('partNumber' => 3, 'checksum' => 'aaa', 'contentHash' => 'bbb', 'size' => 5, 'offset' => 2));
     $this->assertEquals(3, $part->getPartNumber());
     $this->assertEquals('aaa', $part->getChecksum());
     $this->assertEquals('bbb', $part->getContentHash());
     $this->assertEquals(5, $part->getSize());
     $this->assertEquals(2, $part->getOffset());
     $this->assertEquals(array(2, 6), $part->getRange());
     $this->assertEquals('bytes 2-6/*', $part->getFormattedRange());
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public static function fromUploadId(AwsClientInterface $client, UploadIdInterface $uploadId)
 {
     $transferState = new static($uploadId);
     $listParts = $client->getIterator('ListParts', $uploadId->toParams());
     foreach ($listParts as $part) {
         list($firstByte, $lastByte) = explode('-', $part['RangeInBytes']);
         $partSize = (double) $listParts->getLastResult()->get('PartSizeInBytes');
         $partData = array('partNumber' => $firstByte / $partSize + 1, 'checksum' => $part['SHA256TreeHash'], 'contentHash' => self::ALREADY_UPLOADED, 'size' => $lastByte - $firstByte + 1, 'offset' => $firstByte);
         $transferState->addPart(UploadPart::fromArray($partData));
     }
     return $transferState;
 }
 /**
  * Creates an UploadMultipartPart command from an UploadPart object
  *
  * @param UploadPart $part          UploadPart for which to create a command
  * @param bool       $useSourceCopy Whether or not to use the original source or a copy of it
  *
  * @return OperationCommand
  */
 protected function getCommandForPart(UploadPart $part, $useSourceCopy = false)
 {
     // Setup the command with identifying parameters (accountId, vaultName, and uploadId)
     /** @var $command OperationCommand */
     $command = $this->client->getCommand('UploadMultipartPart', $this->state->getUploadId()->toParams());
     $command->set(Ua::OPTION, Ua::MULTIPART_UPLOAD);
     // Get the correct source
     $source = $this->source;
     if ($useSourceCopy) {
         $sourceUri = $this->source->getUri();
         $source = new EntityBody(fopen($sourceUri, 'r'));
     }
     // Add the range, checksum, and the body limited by the range
     $command->set('range', $part->getFormattedRange());
     $command->set('checksum', $part->getChecksum());
     $command->set('ContentSHA256', $part->getContentHash());
     $command->set('body', new ReadLimitEntityBody($source, $part->getSize(), $part->getOffset()));
     return $command;
 }
 /**
  * Updated the upload helper running totals and tree hash with the data from a complete upload part
  *
  * @param UploadPart $part The newly completed upload part
  *
  * @throws OverflowException if the maximum number of allowed upload parts is exceeded
  */
 protected function updateTotals(UploadPart $part)
 {
     // Throw an exception if there are more parts than total allowed
     if ($part->getPartNumber() > self::MAX_NUM_PARTS) {
         // @codeCoverageIgnoreStart
         throw new OverflowException('An archive must be uploaded in ' . self::MAX_NUM_PARTS . ' parts or less.');
         // @codeCoverageIgnoreEnd
     }
     $this->uploadParts[] = $part;
     $this->archiveSize += $part->getSize();
 }
 /**
  * Finalizes the context by calculating the final hashes and generates an upload part object
  *
  * @return UploadPart
  */
 public function generatePart()
 {
     if (!$this->uploadPart) {
         $this->uploadPart = UploadPart::fromArray(array('partNumber' => (int) ($this->offset / $this->maxSize + 1), 'checksum' => $this->treeHash->getHash(), 'contentHash' => $this->chunkHash->getHash(), 'size' => $this->size, 'offset' => $this->offset));
     }
     return $this->uploadPart;
 }