Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9345844
D571.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D571.diff
View Options
diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py
--- a/swh/model/hashutil.py
+++ b/swh/model/hashutil.py
@@ -30,25 +30,26 @@
- To compute length, integrate the length to the set of algorithms to
compute, for example:
- h = MultiHash(hash_names=set({'length'}).union(DEFAULT_ALGORITHMS))
- with open(filepath, 'rb') as f:
- h.update(f.read(HASH_BLOCK_SIZE))
- hashes = h.digest() # returns a dict of {hash_algo_name: hash_in_bytes}
+ .. code-block:: python
- for chunk in
- # then use h as you would
+ h = MultiHash(hash_names=set({'length'}).union(DEFAULT_ALGORITHMS))
+ with open(filepath, 'rb') as f:
+ h.update(f.read(HASH_BLOCK_SIZE))
+ hashes = h.digest() # returns a dict of {hash_algo_name: hash_in_bytes}
- Write alongside computing hashing algorithms (from a stream), example:
- h = MultiHash(length=length)
- with open(filepath, 'wb') as f:
- for chunk in r.iter_content(): # r a stream of sort
- h.update(chunk)
- f.write(chunk)
- hashes = h.hexdigest() # returns a dict of {hash_algo_name: hash_in_hex}
+ .. code-block:: python
+
+ h = MultiHash(length=length)
+ with open(filepath, 'wb') as f:
+ for chunk in r.iter_content(): # r a stream of sort
+ h.update(chunk)
+ f.write(chunk)
+ hashes = h.hexdigest() # returns a dict of {hash_algo_name: hash_in_hex}
- Note: Prior to this, we would have to use chunk_cb (cf. hash_file,
- hash_path)
+ Note: Prior to this, we would have to use chunk_cb (cf. hash_file,
+ hash_path)
This module also defines the following (deprecated) hashing functions:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 3:33 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217369
Attached To
D571: Fix rst formatting errors in hashutil.py
Event Timeline
Log In to Comment