Hash v1 uploads for torrent chunks
This commit is contained in:
parent
44fcc7e44b
commit
8f80d7064b
6 changed files with 98 additions and 69 deletions
|
@ -35,7 +35,8 @@ def make_torrent(name, webseed, length, piece_length, pieces):
|
|||
|
||||
|
||||
class PieceHasher(object):
|
||||
def __init__(self, piece_size, starting_offset, starting_piece_hash_bytes, hash_fragment_to_resume):
|
||||
def __init__(self, piece_size, starting_offset=0, starting_piece_hash_bytes='',
|
||||
hash_fragment_to_resume=None):
|
||||
if not isinstance(starting_offset, (int, long)):
|
||||
raise TypeError('starting_offset must be an integer')
|
||||
elif not isinstance(piece_size, (int, long)):
|
||||
|
@ -43,9 +44,14 @@ class PieceHasher(object):
|
|||
|
||||
self._current_offset = starting_offset
|
||||
self._piece_size = piece_size
|
||||
self._hash_fragment = hash_fragment_to_resume
|
||||
self._piece_hashes = bytearray(starting_piece_hash_bytes)
|
||||
|
||||
if hash_fragment_to_resume is None:
|
||||
self._hash_fragment = resumablehashlib.sha1()
|
||||
else:
|
||||
self._hash_fragment = hash_fragment_to_resume
|
||||
|
||||
|
||||
def update(self, buf):
|
||||
buf_offset = 0
|
||||
while buf_offset < len(buf):
|
||||
|
|
Reference in a new issue