Update the pieces to use base64 encoded binary
This commit is contained in:
parent
5c6e033d21
commit
ce8fcbeaae
4 changed files with 32 additions and 30 deletions
|
@ -2,7 +2,7 @@ import resumablehashlib
|
|||
|
||||
|
||||
class PieceHasher(object):
|
||||
def __init__(self, piece_size, starting_offset, starting_piece_hash_str, hash_fragment_to_resume):
|
||||
def __init__(self, piece_size, starting_offset, starting_piece_hash_bytes, hash_fragment_to_resume):
|
||||
if not isinstance(starting_offset, (int, long)):
|
||||
raise TypeError('starting_offset must be an integer')
|
||||
elif not isinstance(piece_size, (int, long)):
|
||||
|
@ -11,7 +11,7 @@ class PieceHasher(object):
|
|||
self._current_offset = starting_offset
|
||||
self._piece_size = piece_size
|
||||
self._hash_fragment = hash_fragment_to_resume
|
||||
self._piece_hashes = [starting_piece_hash_str]
|
||||
self._piece_hashes = bytearray(starting_piece_hash_bytes)
|
||||
|
||||
def update(self, buf):
|
||||
buf_offset = 0
|
||||
|
@ -21,7 +21,7 @@ class PieceHasher(object):
|
|||
|
||||
if self._piece_offset() == 0 and to_hash_len > 0 and self._current_offset > 0:
|
||||
# We are opening a new piece
|
||||
self._piece_hashes.append(self._hash_fragment.hexdigest())
|
||||
self._piece_hashes.extend(self._hash_fragment.digest())
|
||||
self._hash_fragment = resumablehashlib.sha1()
|
||||
|
||||
self._hash_fragment.update(buf_bytes_to_hash)
|
||||
|
@ -36,7 +36,7 @@ class PieceHasher(object):
|
|||
|
||||
@property
|
||||
def piece_hashes(self):
|
||||
return ''.join(self._piece_hashes)
|
||||
return self._piece_hashes
|
||||
|
||||
@property
|
||||
def hash_fragment(self):
|
||||
|
|
Reference in a new issue