Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: checksum of State #38

Merged
merged 8 commits into from
Nov 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: use chunksize constant
rilshok committed Nov 30, 2024
commit bdb1ba00df2a68c16c189a7d70af8f5b7e896250
4 changes: 3 additions & 1 deletion src/iokit/checksum.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@

Data = State | bytes | BytesIO

CHUNK_SIZE = 4096


@contextmanager
def _buffer(data: Data) -> Generator[BytesIO, None, None]:
@@ -35,7 +37,7 @@ def _buffer(data: Data) -> Generator[BytesIO, None, None]:
def xxh128(data: Data) -> str:
hash_object = xxhash.xxh128()
with _buffer(data) as buffer:
for chunk in iter(lambda: buffer.read(4096), b""):
for chunk in iter(lambda: buffer.read(CHUNK_SIZE), b""):
hash_object.update(chunk)
file_hash = hash_object.hexdigest()
return file_hash