INNER CODE UNIT · Python
worker
ivoyager/planetarium · web/post_export.py:108
worker = worker[:match.start(1)] + cached_files_json + worker[match.end(1):]
with open(worker_path, "w", encoding="utf-8", newline="") as file:
file.write(worker)
print(f"{worker_path.name}: added {SPLASH_IMAGE.name} to CACHED_FILES")
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")