Add matches_handle, matches_file.
This commit is contained in:
parent
d924e273b9
commit
d95d1c9533
1 changed files with 18 additions and 0 deletions
|
@ -37,6 +37,24 @@ def equal_file(filename1, filename2, *args, **kwargs):
|
|||
with open(filename1, 'rb') as handle1, open(filename2, 'rb') as handle2:
|
||||
return equal_handle(handle1, handle2, *args, **kwargs)
|
||||
|
||||
def matches_handle(handle, other_id):
|
||||
(other_size, hashtype, chunk_size, other_hash) = other_id.split('_')
|
||||
other_size = int(other_size)
|
||||
chunk_size = int(chunk_size)
|
||||
|
||||
this_size = handle.seek(0, SEEK_END)
|
||||
handle.seek(0)
|
||||
if this_size != other_size:
|
||||
return False
|
||||
|
||||
this_id = quickid_handle(handle, hashtype=hashtype, chunk_size=chunk_size)
|
||||
return this_id == other_id
|
||||
|
||||
def matches_file(filename, other_id):
|
||||
filename = pathclass.Path(filename).absolute_path
|
||||
with open(filename, 'rb') as handle:
|
||||
return matches_handle(handle, other_id)
|
||||
|
||||
def quickid_handle(handle, hashtype='md5', chunk_size=None):
|
||||
if chunk_size is None:
|
||||
chunk_size = CHUNK_SIZE
|
||||
|
|
Loading…
Reference in a new issue