/** * @expectedException \LogicException * @covers Aws\Glacier\Model\MultipartUpload\UploadPartContext::addData */ public function testCannotAddTooMuchData() { $context = new UploadPartContext(3); $context->addData('foo'); $context->addData('bar'); }
/** * Performs the work of reading the body stream, creating tree hashes, and creating UploadPartContext objects * * @param EntityBodyInterface $body The body to create parts from */ protected function generateUploadParts(EntityBodyInterface $body) { // Rewind the body stream $body->seek(0); // Initialize variables for tracking data for upload $uploadContext = new UploadPartContext($this->partSize, $body->ftell()); // Read the data from the streamed body in 1MB chunks $data = $this->readPart($body); while (strlen($data) > 0) { // Add data to the hashes and size calculations $uploadContext->addData($data); // If the upload part is complete, generate an upload object and reset the currently tracked upload data if ($uploadContext->isFull()) { $this->updateTotals($uploadContext->generatePart()); $uploadContext = new UploadPartContext($this->partSize, $body->ftell()); } $data = $this->readPart($body); } // Handle any leftover data if (!$uploadContext->isEmpty()) { $this->updateTotals($uploadContext->generatePart()); } // Rewind the body stream $body->seek(0); }