Skip to content

Commit 556fd0c

Browse files
authored
Merge branch 'trunk' into fix/s3-stream-chunk-size
2 parents 7ef82bf + b646588 commit 556fd0c

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ Storage
4242
requested chunk size is now passed through to the underlying iterator
4343
instead of the hardcoded default.
4444
(GITHUB-1798)
45+
46+
[Sanjay Santhanam - @Sanjays2402]
47+
48+
- [Azure Blobs] Fix ``chunk_size`` argument being ignored by
49+
``download_object_as_stream`` and ``download_object_range_as_stream``. The
50+
requested chunk size is now forwarded to the underlying iterator instead of
51+
always using ``AZURE_DOWNLOAD_CHUNK_SIZE``.
52+
(GITHUB-1698)
53+
4554
[Sanjay Santhanam - @Sanjays2402]
4655

4756
Changes in Apache Libcloud 3.9.1

libcloud/storage/drivers/azure_blobs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ def download_object_as_stream(self, obj, chunk_size=None):
793793
"""
794794
obj_path = self._get_object_path(obj.container, obj.name)
795795
response = self.connection.request(obj_path, method="GET", stream=True, raw=True)
796-
iterator = response.iter_content(AZURE_DOWNLOAD_CHUNK_SIZE)
796+
iterator = response.iter_content(chunk_size or AZURE_DOWNLOAD_CHUNK_SIZE)
797797

798798
return self._get_object(
799799
obj=obj,
@@ -848,7 +848,7 @@ def download_object_range_as_stream(self, obj, start_bytes, end_bytes=None, chun
848848
response = self.connection.request(
849849
obj_path, method="GET", headers=headers, stream=True, raw=True
850850
)
851-
iterator = response.iter_content(AZURE_DOWNLOAD_CHUNK_SIZE)
851+
iterator = response.iter_content(chunk_size or AZURE_DOWNLOAD_CHUNK_SIZE)
852852
success_status_codes = [httplib.OK, httplib.PARTIAL_CONTENT]
853853

854854
return self._get_object(

libcloud/test/storage/test_azure_blobs.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,40 @@ def test_download_object_as_stream_success(self):
697697
consumed_stream = "".join(chunk.decode("utf-8") for chunk in stream)
698698
self.assertEqual(len(consumed_stream), obj.size)
699699

700+
def test_download_object_as_stream_uses_chunk_size(self):
701+
container = Container(name="foo_bar_container", extra={}, driver=self.driver)
702+
703+
obj = Object(
704+
name="foo_bar_object",
705+
size=1000,
706+
hash=None,
707+
extra={},
708+
container=container,
709+
meta_data=None,
710+
driver=self.driver_type,
711+
)
712+
713+
used_chunk_sizes = []
714+
715+
def mock_get_object(
716+
self, obj, callback, callback_kwargs, response, success_status_code=None
717+
):
718+
iterator = callback_kwargs["iterator"]
719+
used_chunk_sizes.append(iterator.gi_frame.f_locals.get("chunk_size"))
720+
return iterator
721+
722+
old_func = self.driver_type._get_object
723+
self.driver_type._get_object = mock_get_object
724+
try:
725+
self.driver.download_object_as_stream(obj=obj, chunk_size=1234)
726+
self.driver.download_object_range_as_stream(
727+
obj=obj, start_bytes=0, end_bytes=10, chunk_size=4321
728+
)
729+
finally:
730+
self.driver_type._get_object = old_func
731+
732+
self.assertEqual(used_chunk_sizes, [1234, 4321])
733+
700734
def test_download_object_range_success(self):
701735
container = Container(name="foo_bar_container", extra={}, driver=self.driver)
702736
obj = Object(

0 commit comments

Comments
 (0)