Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
Created June 12, 2015 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlohamalainen/14aedb34be4f862334a4 to your computer and use it in GitHub Desktop.
Save carlohamalainen/14aedb34be4f862334a4 to your computer and use it in GitHub Desktop.
Join binary files.
#!/usr/bin/env python
from functools import partial
import sys
BLOCKSIZE = 1048576
# Similar to http://bugs.python.org/issue20992
# but with Python 2.x syntax.
def read_blocks(files):
for filename in files:
with open(filename, "rb") as f:
for block in iter(partial(f.read, BLOCKSIZE), b''):
yield block
if __name__ == '__main__':
files = filter(lambda x: x != '', open(sys.argv[1], 'r').read().split('\n'))
output_file = sys.argv[2]
with open(output_file, 'wb') as f:
for block in read_blocks(files):
f.write(block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment