Skip to content

Commit 1d86fa5

Browse files
committed
default block for computing checksums
1 parent 3fa4bee commit 1d86fa5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/service-library/src/servicelib/file_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import asyncio
22
import hashlib
33
import shutil
4+
from collections.abc import Iterator
45
from contextlib import contextmanager
56
from logging import Logger
67
from pathlib import Path
7-
from typing import Final, Iterator, Protocol
8+
from typing import Final, Protocol
89

910
# https://docs.python.org/3/library/shutil.html#shutil.rmtree
1011
# https://docs.python.org/3/library/os.html#os.remove
@@ -13,11 +14,13 @@
1314
from pydantic import ByteSize, TypeAdapter
1415

1516
CHUNK_4KB: Final[ByteSize] = TypeAdapter(ByteSize).validate_python("4kb") # 4K blocks
17+
CHUNK_8MB: Final[ByteSize] = TypeAdapter(ByteSize).validate_python(
18+
"8MiB"
19+
) # 8mIB blocks
1620

1721

1822
class AsyncStream(Protocol):
19-
async def read(self, size: int = -1) -> bytes:
20-
...
23+
async def read(self, size: int = -1) -> bytes: ...
2124

2225

2326
_shutil_rmtree = sync_to_async(shutil.rmtree)
@@ -45,7 +48,7 @@ async def remove_directory(
4548

4649

4750
async def create_sha256_checksum(
48-
async_stream: AsyncStream, *, chunk_size: ByteSize = CHUNK_4KB
51+
async_stream: AsyncStream, *, chunk_size: ByteSize = CHUNK_8MB
4952
) -> str:
5053
"""
5154
Usage:

0 commit comments

Comments
 (0)