# Cloud Storage Client - Class ReadStream (2.3.0)

2.3.0 (latest) 2.2.0 2.1.0 2.0.0 1.51.0 1.50.0 1.49.2 1.48.7 1.47.0 1.46.0 1.45.0 1.44.0 1.43.1 1.42.1 1.41.4 1.37.0 1.36.1 1.35.0 1.34.0 1.33.4 1.32.0 1.31.2 1.30.3 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. |