Cloud Storage Client - Class ReadStream (1.49.2)

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

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

Namespace

Google \ Cloud \ Storage

Methods

__construct

Create a new ReadStream.

Parameter
NameDescription
streamPsr\Http\Message\StreamInterface

The stream interface to wrap

getSize

Return the full size of the buffer. If the underlying stream doesnot report it's size, try to fetch the size from the Content-Lengthresponse header.

Returns
TypeDescription
intThe size of the stream.

read

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

Parameter
NameDescription
lengthint

The number of bytes to read.

Returns
TypeDescription
stringRead bytes from the underlying stream.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-01-24 UTC.