I've written some code to bz2-compress a file with the BZ2 Compressor Object:
def compressFile(file_name, new_name):
comp = bz2.BZ2Compressor()
comFile = open(new_name, "wb")
oldFile = open(file_name, "rb")
while True:
data = oldFile.read(1024*1024)
if(len(data) == 0):
break
compressed = comp.compress(data)
comFile.write(compressed)
comp.flush()
comFile.close()
I don't get an error and the file is created, but when I want to open it with an archive manager, I get a nonspecific error. I can't find my mistake and this module is poorly documented.