Cloud Storage Client - Class ReadStream (1.31.2)

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
NameDescription
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
TypeDescription
intThe 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
NameDescription
length int

The number of bytes to read.

Returns
TypeDescription
stringRead bytes from the underlying stream.