Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products.

Python 3.10 is now generally available.

google.appengine.ext.blobstore.BlobReader

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

Inherits From: expected_type

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.

ValueError If a BlobKey, BlobInfo, or string blob key is not supplied.

blob_info Returns the BlobInfo for this file.
closed Determines whether a file is closed.

Methods

close

View source

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

next

View source

Returns the next line from the file.

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.

Raises
StopIteration If there are no further lines to read.

read

View source

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.

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

Returns
The read data, as a string.

readline

View source

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.

Args
size Optional. The maximum number of bytes to read.

Returns
The read data, as a string.

readlines

View source

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.

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

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

seek

View source

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

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.

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

tell

View source

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

Returns
The file's current position.

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

truncate

View source

Raises an error if you attempt to truncate the file.

Args
size The size that you are attempting to truncate to.

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

write

View source

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

Args
str The string that you are attempting to write.

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

writelines

View source

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

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

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

__enter__

View source

Attempts to open the file.

Returns
The open file.

__exit__

View source

Closes the file.

__iter__

View source

Retrieves a file iterator for this BlobReader.

Returns
The file iterator for the BlobReader.

SEEK_CUR 1
SEEK_END 2
SEEK_SET 0