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()); }
/** * {@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; }
/** * 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; }