Skip to content

Commit

Permalink
feat: add raw_download kwarg to BlobReader (#668)
Browse files Browse the repository at this point in the history
* feat: add raw_download kwarg to BlobReader

* update docstrings
  • Loading branch information
cojenco committed Dec 15, 2021
1 parent ee41b3f commit 10cdad6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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

0 comments on commit 10cdad6

Please sign in to comment.