GuzzleHttp\Psr7\LimitStream::getSize PHP Method

getSize() public method

Returns the size of the limited subset of data {@inheritdoc}
public getSize ( )
    public function getSize()
    {
        if (null === ($length = $this->stream->getSize())) {
            return null;
        } elseif ($this->limit == -1) {
            return $length - $this->offset;
        } else {
            return min($this->limit, $length - $this->offset);
        }
    }

Usage Example

 /**
  * Triggers the upload process.
  *
  * @return array
  * @throws GoogleException
  */
 public function upload()
 {
     $rangeStart = $this->rangeStart;
     $response = null;
     $resumeUri = $this->getResumeUri();
     $size = $this->data->getSize() ?: '*';
     do {
         $data = new LimitStream($this->data, $this->chunkSize ?: -1, $rangeStart);
         $rangeEnd = $rangeStart + ($data->getSize() - 1);
         $headers = ['Content-Length' => $data->getSize(), 'Content-Type' => $this->contentType, 'Content-Range' => "bytes {$rangeStart}-{$rangeEnd}/{$size}"];
         $request = new Request('PUT', $resumeUri, $headers, $data);
         try {
             $response = $this->requestWrapper->send($request, $this->requestOptions);
         } catch (GoogleException $ex) {
             throw new GoogleException("Upload failed. Please use this URI to resume your upload: {$this->resumeUri}", $ex->getCode());
         }
         $rangeStart = $this->getRangeStart($response->getHeaderLine('Range'));
     } while ($response->getStatusCode() === 308);
     return json_decode($response->getBody(), true);
 }
All Usage Examples Of GuzzleHttp\Psr7\LimitStream::getSize