individually decompressed and "untarred", thanks to be using the
concat gzip tar format.
'''
-
# create sample data
hash = dict()
hash["big"] = self.create_file("big", 50000)
filesplit.split_file(GZ_MAGIC_BYTES, "sample.tar.gz.", "sample.tar.gz")
- assert os.path.exists("sample.tar.gz.0") # beginning of the tar file
- assert os.path.exists("sample.tar.gz.1") # first file
- assert os.path.exists("sample.tar.gz.2") # second file
- assert os.path.exists("sample.tar.gz.3") # third file
- assert not os.path.exists("sample.tar.gz.4") # nothing else
+ assert os.path.exists("sample.tar.gz.0") # first file
+ assert os.path.exists("sample.tar.gz.1") # second file
+ assert os.path.exists("sample.tar.gz.2") # third file
+ assert not os.path.exists("sample.tar.gz.3") # nothing else
# extract and check output
- for i in range(1, 4):
+ for i in range(0, 3):
tarobj = TarFile.open("sample.tar.gz.%d" % i,
mode="r|gz")
tarobj.extractall()
# extract using the command line this time
os.system("python3 filesplit.py -s $'\\x1f\\x8b' -p sample.tar.gz. sample.tar.gz")
- assert os.path.exists("sample.tar.gz.0") # beginning of the tar file
- assert os.path.exists("sample.tar.gz.1") # first file
- assert os.path.exists("sample.tar.gz.2") # second file
- assert os.path.exists("sample.tar.gz.3") # third file
- assert not os.path.exists("sample.tar.gz.4") # nothing else
+ assert os.path.exists("sample.tar.gz.0") # first file
+ assert os.path.exists("sample.tar.gz.1") # second file
+ assert os.path.exists("sample.tar.gz.2") # third file
+ assert not os.path.exists("sample.tar.gz.3") # nothing else
# extract and check output
- for i in range(1, 4):
+ for i in range(0, 3):
os.system("gzip -cd sample.tar.gz.%d > sample.%d.tar" % (i, i))
os.system("tar xf sample.%d.tar" % i)
# equivalent to $ python filesplit.py -s $'\x1f\x8b' -p sample.tar.gz. sample.tar.gz
filesplit.split_file(GZ_MAGIC_BYTES, "sample.tar.gz.", "sample.tar.gz")
- assert os.path.exists("sample.tar.gz.0") # beginning of the tar file
- assert os.path.exists("sample.tar.gz.1") # first file
- assert os.path.exists("sample.tar.gz.2") # second file
- assert os.path.exists("sample.tar.gz.3") # third file
- assert not os.path.exists("sample.tar.gz.4") # nothing else
+ assert os.path.exists("sample.tar.gz.0") # first file
+ assert os.path.exists("sample.tar.gz.1") # second file
+ assert os.path.exists("sample.tar.gz.2") # third file
+ assert not os.path.exists("sample.tar.gz.3") # nothing else
# extract and check output
- for i in range(1, 4):
+ for i in range(0, 3):
try:
tarobj = TarFile.open("sample.tar.gz.%d" % i,
mode="r|gz")
tarobj.extractall()
tarobj.close()
except Exception as e:
- if i == 1: # big file doesn't extract well because it's corrupted
+ if i == 0: # big file doesn't extract well because it's corrupted
pass
else:
raise Exception("Error extracting a tar.gz not related to the broken 'big' file")