Page MenuHomeSoftware Heritage

D571.diff
No OneTemporary

D571.diff

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

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

Event Timeline