Cloud Storage Client - Class ReadStream (1.44.0)

Reference documentation and code samples for the Cloud Storage Client class ReadStream.

A Stream implementation that wraps a GuzzleHttp download stream to provide getSize() from the response headers.

Namespace

Google \ Cloud \ Storage

Methods

__construct

Create a new ReadStream.

Parameter
Name Description
stream Psr\Http\Message\StreamInterface

The stream interface to wrap

getSize

Return the full size of the buffer. If the underlying stream does not report it's size, try to fetch the size from the Content-Length response header.

Returns
Type Description
int The size of the stream.

read

Read bytes from the underlying buffer, retrying until we have read enough bytes or we cannot read any more. We do this because the internal C code for filling a buffer does not account for when we try to read large chunks from a user-land stream that does not return enough bytes.

Parameter
Name Description
length int

The number of bytes to read.

Returns
Type Description
string Read bytes from the underlying stream.