# google.appengine.ext.blobstore.BlobReader

<br />

|---|
| [View source on GitHub](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L866-L1191) |

Provides a read-only file-like interface to a blobstore blob.

Inherits From: [`expected_type`](https://docs.cloud.google.com/appengine/docs/standard/python3/reference/services/bundled/google/appengine/api/validation/Validator/expected_type)

#### View aliases


**Main aliases**

\`google.appengine.ext.blobstore.blobstore.BlobReader\`

<br />

    google.appengine.ext.blobstore.BlobReader(
        blob, buffer_size=131072, position=0
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `blob` | The blob key, blob info, or string blob key to read from. |
| `buffer_size` | The minimum size to fetch chunks of data from blobstore. |
| `position` | The initial position in the file. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If a `BlobKey`, `BlobInfo`, or string blob key is not supplied. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `blob_info` | Returns the `BlobInfo` for this file. |
| `closed` | Determines whether a file is closed. |

<br />

## Methods

### `close`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L920-L927)

    close()

Closes the file.

A closed file cannot be read or written to anymore. An operation that
requires that the file to be open will raise a `ValueError` after the file
has been closed. Calling `close()` more than once is allowed.

### `flush`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L929-L930)

    flush()

### `next`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L932-L945)

    next()

Returns the next line from the file.

<br />

<br />

<br />

| Returns ||
|---|---|
| A string, terminated by `\\n`. The last line cannot end with `\\n`. If the end of the file is reached, an empty string will be returned. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `StopIteration` | If there are no further lines to read. |

<br />

### `read`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1004-L1029)

    read(
        size=-1
    )

Reads at most `size` bytes from the file.

Fewer bytes are read if the read hits the end of the file before obtaining
`size` bytes. If the `size` argument is negative or omitted, all data is
read until the end of the file is reached. The bytes are returned as a
string object. An empty string is returned immediately when the end of the
file is reached.

Calling `read()` without specifying a `size` is likely to be dangerous, as
it might read excessive amounts of data.

<br />

<br />

<br />

| Args ||
|---|---|
| `size` | Optional. The maximum number of bytes to read. When omitted, `read()` returns all remaining data in the file. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The read data, as a string. ||

<br />

### `readline`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1031-L1066)

    readline(
        size=-1
    )

Reads one entire line from the file.

A trailing newline character is kept in the string but can be absent when a
file ends with an incomplete line. If the `size` argument is present and
non-negative, it represents a maximum byte count, including the trailing
newline and an incomplete line might be returned. An empty string is
returned immediately only when the end of the file is reached.

<br />

<br />

<br />

| Args ||
|---|---|
| `size` | Optional. The maximum number of bytes to read. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The read data, as a string. ||

<br />

### `readlines`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1068-L1092)

    readlines(
        sizehint=None
    )

Reads until the end of the file using `readline()`.

A list of lines read is returned.

If the optional `sizehint` argument is present, instead of reading up to the
end of the file, whole lines totalling approximately `sizehint` bytes are
read, possibly after rounding up to an internal buffer size.

<br />

<br />

<br />

| Args ||
|---|---|
| `sizehint` | A hint as to the maximum number of bytes to read. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A list of strings, each being a single line from the file. ||

<br />

### `seek`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1094-L1115)

    seek(
        offset, whence=SEEK_SET
    )

Sets the file's current position, like stdio's `fseek()`_.

<br />

<br />

<br />

| Args ||
|---|---|
| `offset` | The relative offset to seek to. |
| `whence` | Optional; defines to what value the offset is relative. This argument defaults to `os.SEEK_SET` or `0` to use absolute file positioning; other valid values are `os.SEEK_CUR` or `1` to seek relative to the current position and `os.SEEK_END` or `2` to seek relative to the end of the file. |

<br />

.. _fseek():
http://www.cplusplus.com/reference/cstdio/fseek/

### `tell`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1117-L1126)

    tell()

Retrieves the file's current position, like stdio's `ftell()`_.

<br />

<br />

<br />

| Returns ||
|---|---|
| The file's current position. ||

<br />

.. _ftell():
http://www.cplusplus.com/reference/cstdio/ftell/

### `truncate`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1128-L1137)

    truncate(
        size
    )

Raises an error if you attempt to truncate the file.

<br />

<br />

<br />

| Args ||
|---|---|
| `size` | The size that you are attempting to truncate to. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `IOError` | If you attempt to truncate a file in `BlobReader`. |

<br />

### `write`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1139-L1148)

    write(
        str
    )

Raises an error if you attempt to write to the file.

<br />

<br />

<br />

| Args ||
|---|---|
| `str` | The string that you are attempting to write. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `IOError` | If you attempt to write to a file in `BlobReader`. |

<br />

### `writelines`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1150-L1159)

    writelines(
        sequence
    )

Raises an error if you attempt to write to the file.

<br />

<br />

<br />

| Args ||
|---|---|
| `sequence` | The sequence of strings that you are attempting to write. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `IOError` | If you attempt to write lines to a file in `BlobReader`. |

<br />

### `__enter__`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1181-L1187)

    __enter__()

Attempts to open the file.

<br />

<br />

<br />

| Returns ||
|---|---|
| The open file. ||

<br />

### `__exit__`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L1189-L1191)

    __exit__(
        exc_type, exc_value, traceback
    )

Closes the file.

### `__iter__`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/ext/blobstore/blobstore.py#L899-L906)

    __iter__()

Retrieves a file iterator for this `BlobReader`.

<br />

<br />

<br />

| Returns ||
|---|---|
| The file iterator for the `BlobReader`. ||

<br />

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| SEEK_CUR | `1` |
| SEEK_END | `2` |
| SEEK_SET | `0` |

<br />