When you use a BZ2Compressor
, you get data in chunks when you call compress()
, and a good chance is that you only get the data when you call flush()
.
It should work if you change your function like this:
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
comFile.write(comp.compress(data))
comFile.write(comp.flush())
comFile.close()