I want to emulate the behavior of gzip -d <file.gz>
within a Python script.
The compressed GZIP file is decompressed and written as a file with the same file name as the original GZIP file without the .gz extension.
file.abc.gz --> file.abc
It's not obvious how to do this using the gzip library, all the examples in the docs are for compressing data arrays, and I've not yet found a good example from research.
Edit
I've tried the below using tarfile module, but unfortunately it's not working, I think since the GZIP file wasn't created with tar.
# get the zipped file's contents list, extract the file
with tarfile.TarFile(local_zipped_filename) as tar_file:
# list the contents, make sure we only extract the expected named file
members = tar_file.getmembers()
for member in members:
if member.name == filename_unzipped:
members_to_extract = [member]
tar_file.extractall(path=destination_dir, members=members_to_extract)
break # we've extracted our file, done