Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def almost_not_slow():
- CHANNELS = 16
- SAMPLE_LENGTH = CHANNELS // 8
- BUFFER = 256
- vals = {}
- for i in range(2**CHANNELS):
- vals[struct.pack('H', i)] = tuple(b'+1' if e == '1' else b'-1' for e in list("{:016b}".format(i)))
- with open('largefile.dat', 'rb') as f:
- data = f.read()
- size = len(data)
- print("Data size: %d" % size)
- out_file = open('largefile_dump.dat', 'wb')
- out_list = [out_file]*CHANNELS
- samples = ()
- for i in range(0, size, SAMPLE_LENGTH):
- if i % (1024*1024) == 0: print("i = %d" % i)
- samples = samples + (vals[data[i:i+SAMPLE_LENGTH]],)
- if len(samples) == BUFFER:
- for channel in range(CHANNELS):
- s = b'\n'.join(r[channel] for r in samples)
- out_list[channel].write(s)
- samples = ()
- if samples:
- for channel in range(CHANNELS):
- s = b'\n'.join(r[channel] for r in samples)
- out_list[channel].write(s)
- out_file.close()
Add Comment
Please, Sign In to add comment