File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed
src/servicelib/zip_stream Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 11from typing import Final
22
3- _KB : Final [ int ] = 1024
3+ from pydantic import ByteSize , TypeAdapter
44
5- DEFAULT_CHUNK_SIZE : Final [int ] = 64 * _KB
5+ DEFAULT_CHUNK_SIZE : Final [int ] = TypeAdapter ( ByteSize ). validate_python ( "1MiB" )
Original file line number Diff line number Diff line change @@ -27,11 +27,19 @@ async def _iter_files(
2727
2828
2929async def get_zip_archive_stream (
30- archive_files : ArchiveEntries , * , progress_bar : ProgressBarData | None = None
30+ archive_files : ArchiveEntries ,
31+ * ,
32+ progress_bar : ProgressBarData | None = None ,
33+ chunk_size : int = DEFAULT_CHUNK_SIZE
3134) -> FileStream :
35+ # NOTE: this is CPU bound task, even though the loop is not blocked,
36+ # the CPU is still used for compressing the content
3237 if progress_bar is None :
3338 progress_bar = ProgressBarData (num_steps = 1 , description = "stream archiver" )
39+
40+ # NOTE: do not disable compression or the streams will be
41+ # loaded fully in memory before yielding their content
3442 async for chunk in async_stream_zip (
35- _iter_files (archive_files , progress_bar ), chunk_size = DEFAULT_CHUNK_SIZE
43+ _iter_files (archive_files , progress_bar ), chunk_size = chunk_size
3644 ):
3745 yield chunk
Original file line number Diff line number Diff line change 1010from faker import Faker
1111from pytest_mock import MockerFixture
1212from pytest_simcore .helpers .comparing import (
13- assert_same_folder_contents ,
14- get_files_in_folder ,
13+ assert_same_contents ,
14+ get_files_info_from_path ,
1515 get_relative_to ,
1616)
1717from servicelib .archiving_utils import unarchive_dir
@@ -121,7 +121,7 @@ async def test_get_zip_archive_stream(
121121 await unarchive_dir (local_archive_path , local_unpacked_archive )
122122
123123 # 3. compare files in directories (same paths & sizes)
124- await assert_same_folder_contents (
125- get_files_in_folder (local_files_dir ),
126- get_files_in_folder (local_unpacked_archive ),
124+ await assert_same_contents (
125+ get_files_info_from_path (local_files_dir ),
126+ get_files_info_from_path (local_unpacked_archive ),
127127 )
You can’t perform that action at this time.
0 commit comments