File Decompression

Decompress a gzip file back to plain text.

PythonIntermediate
Python
# Program to decompress a gzip file

import gzip

src = input("Enter source gzip filename: ")
dst = input("Enter destination text filename: ")

try:
    with gzip.open(src, "rb") as f_in, open(dst, "wb") as f_out:
        f_out.writelines(f_in)
    print("Decompressed", src, "to", dst)
except FileNotFoundError:
    print("Source gzip file not found.")

Output

Enter source gzip filename: notes.txt.gz
Enter destination text filename: notes_copy.txt
Decompressed notes.txt.gz to notes_copy.txt

Reverses the compression process by reading from gzip and writing raw bytes to a normal file.