8000 feat: add raw_download kwarg to BlobReader (#668) · googleapis/python-storage@10cdad6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10cdad6

Browse files
authored
feat: add raw_download kwarg to BlobReader (#668)
* feat: add raw_download kwarg to BlobReader * update docstrings
1 parent ee41b3f commit 10cdad6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

google/cloud/storage/blob.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,10 @@ def open(
38503850
- ``timeout``
38513851
- ``retry``
38523852
3853+
For downloads only, the following additional arguments are supported:
3854+
3855+
- ``raw_download``
3856+
38533857
For uploads only, the following additional arguments are supported:
38543858
38553859
- ``content_type``
@@ -3877,7 +3881,7 @@ def open(
38773881
>>> client = storage.Client()
38783882
>>> bucket = client.bucket("bucket-name")
38793883
3880-
>>> blob = bucket.get_blob("blob-name.txt")
3884+
>>> blob = bucket.blob("blob-name.txt")
38813885
>>> with blob.open("rt") as f:
38823886
>>> print(f.read())
38833887

google/cloud/storage/fileio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"if_metageneration_not_match",
3636
"timeout",
3737
"retry",
38+
"raw_download",
3839
}
3940

4041
# Valid keyword arguments for upload methods.

tests/unit/test_fileio.py

Lines changed: 18 additions & 0 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ def read_from_fake_data(start=0, end=None, **_):
109109

110110
reader.close()
111111

112+
def test_read_with_raw_download(self):
113+
blob = mock.Mock()
114+
115+
def read_from_fake_data(start=0, end=None, **_):
116+
return TEST_BINARY_DATA[start:end]
117+
118+
blob.download_as_bytes = mock.Mock(side_effect=read_from_fake_data)
119+
download_kwargs = {"raw_download": True}
120+
reader = self._make_blob_reader(blob, chunk_size=8, **download_kwargs)
121+
122+
# Read and trigger the first download of chunk_size.
123+
self.assertEqual(reader.read(1), TEST_BINARY_DATA[0:1])
124+
blob.download_as_bytes.assert_called_once_with(
125+
start=0, end=8, checksum=None, retry=DEFAULT_RETRY, raw_download=True
126+
)
127+
128+
reader.close()
129+
112130
def test_retry_passed_through(self):
113131
blob = mock.Mock()
114132

0 commit comments

Comments
 (0)
0