Skip to content

Commit 905c463

Browse files
Remove dead code: uuid_from_file and uuid_from_stream
- uuid_from_file was never called anywhere in the codebase - uuid_from_stream only existed to support uuid_from_file - Inlined the logic directly into uuid_from_buffer - Removed unused io and pathlib imports Co-authored-by: dimitri-yatsenko <[email protected]>
1 parent 691edcc commit 905c463

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/datajoint/hash.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import hashlib
2-
import io
32
import uuid
4-
from pathlib import Path
53

64

75
def key_hash(mapping):
@@ -16,24 +14,14 @@ def key_hash(mapping):
1614
return hashed.hexdigest()
1715

1816

19-
def uuid_from_stream(stream, *, init_string=""):
17+
def uuid_from_buffer(buffer=b"", *, init_string=""):
2018
"""
21-
:return: 16-byte digest of stream data
22-
:stream: stream object or open file handle
23-
:init_string: string to initialize the checksum
19+
Compute MD5 hash of buffer data, returned as UUID.
20+
21+
:param buffer: bytes to hash
22+
:param init_string: string to initialize the checksum (for namespacing)
23+
:return: UUID based on MD5 digest
2424
"""
2525
hashed = hashlib.md5(init_string.encode())
26-
chunk = True
27-
chunk_size = 1 << 14
28-
while chunk:
29-
chunk = stream.read(chunk_size)
30-
hashed.update(chunk)
26+
hashed.update(buffer)
3127
return uuid.UUID(bytes=hashed.digest())
32-
33-
34-
def uuid_from_buffer(buffer=b"", *, init_string=""):
35-
return uuid_from_stream(io.BytesIO(buffer), init_string=init_string)
36-
37-
38-
def uuid_from_file(filepath, *, init_string=""):
39-
return uuid_from_stream(Path(filepath).open("rb"), init_string=init_string)

0 commit comments

Comments
 (0)