INNER CODE UNIT · Python

gzip_in_place

ivoyager/planetarium · web/post_export.py:114

def gzip_in_place(path):
    """Replace a file with its gzipped copy, as gzip does, unless that's done already."""
    if not path.is_file():
        print(f"{path.name}: already gzipped")
        return
    gz_path = path.with_name(path.name + ".gz")
    with open(path, "rb") as source, gzip.open(gz_path, "wb", compresslevel=9) as target:
        shutil.copyfileobj(source, target, 1 << 20)
    size = path.stat().st_size
    path.unlink()
    print(f"{path.name}: {size / 1e6:.1f} MB -> {gz_path.name}: {gz_path.stat().st_size / 1e6:.1f} MB")


def delete_boot_splash(path):
    if not path.is_file():
        return
    path.unlink()
    print(f"{path.name}: deleted")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…