random.seed(open(TARGET, 'rb').read(1024)) set_min_block_size(1024) set_max_block_size(2048) set_average_block_size(1024) r = Rabin() before = get_file_fingerprints(TARGET) f = open(TARGET, 'rb+') data = f.read(int(filesizeM / 2 * Mb)) r.update(data) r.update(b'x') data = f.read() r.update(data) after = r.fingerprints() assert len(before) <= len(after) diffcount = 0 for i in range(len(before)): try: bs, bl, bp = before[i] As, al, ap = after[i] # assert bs == As assert bl == al assert bp == ap except: print('before', before[i]) print('after', after[i]) diffcount += 1
random.seed(open(TARGET, 'r').read(1024)) set_min_block_size(1024) set_max_block_size(2048) set_average_block_size(1024) r = Rabin() before = get_file_fingerprints(TARGET) f = open(TARGET, 'r+') data = f.read(filesizeM/2 * Mb) r.update(data) r.update('x') data = f.read() r.update(data) after = r.fingerprints() assert len(before) <= len(after) diffcount = 0 for i in range(len(before)): try: bs,bl,bp = before[i] As,al,ap = after[i] # assert bs == As assert bl == al assert bp == ap except: print 'before', before[i] print 'after', after[i] diffcount += 1
def block_reached(start, length, fingerprint): # print('(%s, %s, %s)' % (start, length, fingerprint)) reached.append((start, length, fingerprint)) r = Rabin() r.register(block_reached) with open(TARGET, 'rb') as f: while True: size = random.randint(1,os.path.getsize(TARGET)) data = f.read(size) if len(data) == 0: break r.update(data) partial = r.fingerprints() gold = get_file_fingerprints(TARGET) assert len(gold) == len(partial) == len(reached) for i in range(len(gold)): try: gs,gl,gp = gold[i] ps,pl,pp = partial[i] rs,rl,rp = reached[i] assert gs == ps == rs assert gl == pl == rl assert gp == pp == rp except: print('gold ', gold[i]) print('partial', partial[i])
# print('(%s, %s, %s)' % (start, length, fingerprint)) reached.append((start, length, fingerprint)) r = Rabin() r.register(block_reached) with open(TARGET, 'rb') as f: while True: size = random.randint(1, os.path.getsize(TARGET)) data = f.read(size) if len(data) == 0: break r.update(data) partial = r.fingerprints() gold = get_file_fingerprints(TARGET) assert len(gold) == len(partial) == len(reached) for i in range(len(gold)): try: gs, gl, gp = gold[i] ps, pl, pp = partial[i] rs, rl, rp = reached[i] assert gs == ps == rs assert gl == pl == rl assert gp == pp == rp except: print('gold ', gold[i]) print('partial', partial[i])