I use code that below to create tgz file. When I try to exract tgz file after compress, then I have problem on Linux. But when I try on FreeBSD, it extracts successfull.
import tarfile
import os
def create_tgzfile(output_filename, source_dir,item_list):
os.chdir(source_dir)
tar = tarfile.open(output_filename+".tar.gz", "w")
for name in item_list:
tar.add(name)
tar.close()
create_tgzfile("test","./",["file1","file2"])
test.tgz
exract on FreeBSD
tar -xzvf test.tgz
x file1
x file2
exract on Linux
tar -xzvf test.tgz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
So, why it doesnt open on Linux or How to create correct tgz file with python?