Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add blob.open() for file-like I/O #385

Merged
merged 9 commits into from Mar 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion google/cloud/storage/blob.py
Expand Up @@ -3426,6 +3426,13 @@ def open(
This method can be used as a context manager, just like Python's
built-in 'open()' function.

While reading, as with other read methods, if blob.generation is not set
the most recent blob generation will be used. Because the file-like IO
reader downloads progressively in chunks, this could result in data from
multiple versions being mixed together. If this is a concern, use
either bucket.get_blob(), or blob.reload(), which will download the
latest generation number and set it.
andrewsg marked this conversation as resolved.
Show resolved Hide resolved

:type mode: str
andrewsg marked this conversation as resolved.
Show resolved Hide resolved
:param mode:
(Optional) A mode string, as per standard Python `open()` semantics.The first
Expand Down Expand Up @@ -3485,7 +3492,7 @@ def open(
>>> client = storage.Client()
>>> bucket = client.bucket("bucket-name")

>>> blob = bucket.blob("blob-name.txt")
>>> blob = bucket.get_blob("blob-name.txt")
andrewsg marked this conversation as resolved.
Show resolved Hide resolved
>>> with blob.open("rt") as f:
>>> print(f.read())

Expand Down