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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add raw_download kwarg to BlobReader #668

Merged
merged 2 commits into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion google/cloud/storage/blob.py
Expand Up @@ -3850,6 +3850,10 @@ def open(
- ``timeout``
- ``retry``

For downloads only, the following additional arguments are supported:

- ``raw_download``

For uploads only, the following additional arguments are supported:

- ``content_type``
Expand Down Expand Up @@ -3877,7 +3881,7 @@ def open(
>>> client = storage.Client()
>>> bucket = client.bucket("bucket-name")

>>> blob = bucket.get_blob("blob-name.txt")
>>> blob = bucket.blob("blob-name.txt")
>>> with blob.open("rt") as f:
>>> print(f.read())

Expand Down
1 change: 1 addition & 0 deletions google/cloud/storage/fileio.py
Expand Up @@ -35,6 +35,7 @@
"if_metageneration_not_match",
"timeout",
"retry",
"raw_download",
}

# Valid keyword arguments for upload methods.
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_fileio.py
Expand Up @@ -109,6 +109,24 @@ def read_from_fake_data(start=0, end=None, **_):

reader.close()

def test_read_with_raw_download(self):
blob = mock.Mock()

def read_from_fake_data(start=0, end=None, **_):
return TEST_BINARY_DATA[start:end]

blob.download_as_bytes = mock.Mock(side_effect=read_from_fake_data)
download_kwargs = {"raw_download": True}
reader = self._make_blob_reader(blob, chunk_size=8, **download_kwargs)

# Read and trigger the first download of chunk_size.
self.assertEqual(reader.read(1), TEST_BINARY_DATA[0:1])
blob.download_as_bytes.assert_called_once_with(
start=0, end=8, checksum=None, retry=DEFAULT_RETRY, raw_download=True
)

reader.close()

def test_retry_passed_through(self):
blob = mock.Mock()

Expand Down