#!/usr/bin/env python # s p a r s i fy v0.1 # by itsnotabigtruck # # This program is free software. It comes without any warranty, to the extent # permitted by applicable law. You can redistribute it and/or modify it under # the terms of the Do What The Fuck You Want To Public License, Version 2, as # published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more # details. import itertools import lzo import os import struct import sys def append_chunk(data, dest): # Emit an LZO-compressed chunk m1 = 0xb8c3b410 m2 = 0 origLen = len(data) if origLen > 0: compData = lzo.compress(data)[5:] compLen = len(compData) if compLen >= origLen: compData = data compLen = origLen comp = 0 else: comp = 1 else: compData = data comp = 0 compLen = origLen hdr = struct.pack(" 1016: raise IOError("too many sparse regions to represent") sys.stderr.write("NAME: {0}\n".format(name)) sys.stderr.write("SEGMENTS: {0}\n".format(len(blocks))) sys.stderr.write("BLOCKS READ: {0}\n".format(offset)) sys.stderr.write("BLOCKS WRITTEN: {0}\n".format(totalBlocks)) # Generate a properly formatted header from the block info magic = 0xadaea9a1 hdr = struct.pack(" \n") sys.exit(1) inPath = sys.argv[1] outPath = sys.argv[2] # Encode the data try: inName = os.path.basename(inPath) if len(inName) == 0 or len(inName) > 56: raise IOError("invalid filename (must be <= 56 characters)") with open(inPath, "rb") as inFile, open(outPath, "wb") as outFile: encode_file(inName, inFile, outFile) except: sys.stderr.write("ERROR: " + str(sys.exc_info()[1]) + "\n") sys.exit(1) if __name__ == "__main__": main()