extension = ":gz"
shutil_extension = "gztar"
extension_removal_index = 7 // Hardcode number of indices to be skipped from the end to obtain filename. This is hard-coded as filenames containing "." might exist and thus filepath.split(".") would give an incorrect result.
elif tar_filepath.lower().endswith("bz2"):
extension = ":bz2"
shutil_extension = "bztar"
extension_removal_index = 7
After Change
// Create a tempfile to store the images contain noise
with tempfile.TemporaryDirectory(dir=root_dir) as temp_dir:
// Checking the extension of file to be extract
tar_filepath_lowercase = tar_filepath.lower()
if tar_filepath_lowercase.endswith("gz"):
extension = ":gz"
shutil_extension = "gztar"
if tar_filepath_lowercase.endswith("tgz"):
extension_removal_index = len(".tgz") // Obtain file name from filepath. Hardcoded indices are used as filenames may contain periods
else:
extension_removal_index = len(".tar.gz")
elif tar_filepath_lowercase.endswith("bz2"):
extension = ":bz2"
shutil_extension = "bztar"
extension_removal_index = len(".tar.bz2")
elif tar_filepath_lowercase.endswith("xz"):
extension = ":xz"
shutil_extension = "xztar"
extension_removal_index = len(".tar.xz")
else:
extension = ""
shutil_extension = "tar"
extension_removal_index = -tar_filepath.find(".tar")