MCPcopy Create free account
hub / github.com/datapane/datapane / compress_file

Function compress_file

python-client/src/datapane/common/ops_utils.py:73–83  ·  view source on GitHub ↗

(X-Plat) Return path to a compressed version of the input filename

(f_name: NPath, level: int = 6)

Source from the content-addressed store, hash-verified

71
72@contextmanager
73def compress_file(f_name: NPath, level: int = 6) -> t.Generator[str, None, None]:
74 """(X-Plat) Return path to a compressed version of the input filename"""
75 f_name_gz = f"{f_name}.gz"
76 with open(f_name, "rb") as f_in, gzip.open(f_name_gz, "wb", compresslevel=level) as f_out:
77 shutil.copyfileobj(f_in, f_out)
78 try:
79 yield f_name_gz
80 finally:
81 # NOTE - disable on windows temporarily
82 if not ON_WINDOWS:
83 os.unlink(f_name_gz)
84
85
86def inmemory_compress(content: t.BinaryIO) -> t.BinaryIO:

Callers

nothing calls this directly

Calls 1

openMethod · 0.80

Tested by

no test coverage detected