コード例 #1
0
 private function readPart(EntityBodyInterface $body, $max = Size::MB)
 {
     return $body->read(min($this->partSize, $max));
 }
コード例 #2
0
 /**
  * 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
     while ($data = $body->read(min($this->partSize, Size::MB))) {
         // 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());
         }
     }
     // Handle any leftover data
     if (!$uploadContext->isEmpty()) {
         $this->updateTotals($uploadContext->generatePart());
     }
     // Rewind the body stream
     $body->seek(0);
 }