# Class BlobReader (3.12.0)

3.12.0 (latest) 3.11.0 3.10.1 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0 3.4.1 3.3.1 3.2.0 3.1.1 3.0.0 2.19.0 2.17.0 2.16.0 2.15.0 2.14.0 2.13.0 2.12.0 2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.1 2.1.0 2.0.0 1.44.0 1.43.0 1.42.3 1.41.1 1.40.0 1.39.0 1.38.0 1.37.1 1.36.2 1.35.1 1.34.0 1.33.0 1.32.0 1.31.2 1.30.0 1.29.0 1.28.1 1.27.0 1.26.0 1.25.0 1.24.1 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.0 1.17.0

    BlobReader(
        blob,
        chunk_size=None,
        retry=google.api_core.retry.retry_unary.Retry,
        **download_kwargs
    )

A file-like object that reads from a blob.

| ## Parameters ||
|---|---|
| **Name** | **Description** |
| `download_kwargs` | `dict` Keyword arguments to pass to the underlying API calls. The following arguments are supported: - `if_generation_match` - `if_generation_not_match` - `if_metageneration_match` - `if_metageneration_not_match` - `timeout` - `raw_download` - `single_shot_download` Note that download_kwargs (excluding `raw_download` and `single_shot_download`) are also applied to blob.reload(), if a reload is needed during seek(). |
| `blob` | `'https://docs.cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.blob.Blob'` The blob to download. |
| `chunk_size` | `long` (Optional) The minimum number of bytes to read at a time. If fewer bytes than the chunk_size are requested, the remainder is buffered. The default is the chunk_size of the blob, or 40MiB. |
| `retry` | `google.api_core.retry.Retry or https://docs.cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.retry.ConditionalRetryPolicy` (Optional) How to retry the RPC. A None value will disable retries. A google.api_core.retry.Retry value will enable retries, and the object will define retriable response codes and errors and configure backoff and timeout options. A [google.cloud.storage.retry.ConditionalRetryPolicy](https://docs.cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.retry.ConditionalRetryPolicy) value wraps a Retry object and activates it only if certain conditions are met. This class exists to provide safe defaults for RPC calls that are not technically safe to retry normally (due to potential data duplication or other side-effects) but become safe to retry if a condition such as if_metageneration_match is set. See the retry.py source code and docstrings in this package ([google.cloud.storage.retry](https://docs.cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.retry)) for information on retry types and how to configure them. Media operations (downloads and uploads) do not support non-default predicates in a Retry object. The default will always be used. Other configuration changes for Retry objects such as delays and deadlines are respected. |

## Methods

### close

    close()

Flush and close the IO object.

This method has no effect if the file is already closed.

### read

    read(size=-1)

Read and return up to n bytes.

If the argument is omitted, None, or negative, reads and
returns all data until EOF.

If the argument is positive, and the underlying raw stream is
not 'interactive', multiple raw reads may be issued to satisfy
the byte count (unless EOF is reached first). But for
interactive raw streams (as well as sockets and pipes), at most
one raw read will be issued, and a short result does not imply
that EOF is imminent.

Returns an empty bytes object on EOF.

Returns None if the underlying raw stream was open in non-blocking
mode and no data is available at the moment.

### read1

    read1(size=-1)

Read and return up to n bytes, with at most one read() call
to the underlying raw stream. A short result does not imply
that EOF is imminent.

Returns an empty bytes object on EOF.

### readable

    readable()

Return whether object was opened for reading.

If False, read() will raise OSError.

### seek

    seek(pos, whence=0)

Seek within the blob.

This implementation of seek() uses knowledge of the blob size to
validate that the reported position does not exceed the blob last byte.
If the blob size is not already known it will call blob.reload().

### seekable

    seekable()

Return whether object supports random access.

If False, seek(), tell() and truncate() will raise OSError.
This method may need to do a test seek().

### writable

    writable()

Return whether object was opened for writing.

If False, write() will raise OSError.