MCPcopy Create free account
hub / github.com/dask/dask / hash_buffer

Function hash_buffer

dask/hashing.py:73–91  ·  view source on GitHub ↗

Hash a bytes-like (buffer-compatible) object. This function returns a good quality hash but is not cryptographically secure. The fastest available algorithm is selected. A fixed-length bytes object is returned.

(buf, hasher=None)

Source from the content-addressed store, hash-verified

71
72
73def hash_buffer(buf, hasher=None):
74 """
75 Hash a bytes-like (buffer-compatible) object. This function returns
76 a good quality hash but is not cryptographically secure. The fastest
77 available algorithm is selected. A fixed-length bytes object is returned.
78 """
79 if hasher is not None:
80 try:
81 return hasher(buf)
82 except (TypeError, OverflowError):
83 # Some hash libraries may have overly-strict type checking,
84 # not accepting all buffers
85 pass
86 for hasher in hashers:
87 try:
88 return hasher(buf)
89 except (TypeError, OverflowError):
90 pass
91 raise TypeError(f"unsupported type for hashing: {type(buf)}")
92
93
94def hash_buffer_hex(buf, hasher=None):

Callers 2

test_hash_bufferFunction · 0.90
hash_buffer_hexFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_hash_bufferFunction · 0.72