(X-Plat) Return path to a compressed version of the input filename
(f_name: NPath, level: int = 6)
| 71 | |
| 72 | @contextmanager |
| 73 | def 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 | |
| 86 | def inmemory_compress(content: t.BinaryIO) -> t.BinaryIO: |