Skip to content

Instantly share code, notes, and snippets.

@mbforbes
Created April 12, 2018 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbforbes/89c6b4512cae460eca74b490d19c113b to your computer and use it in GitHub Desktop.
Save mbforbes/89c6b4512cae460eca74b490d19c113b to your computer and use it in GitHub Desktop.
Python compress file
def compress(bytes_path: str, compressed_path: str) -> None:
logging.info('Compressing "{}" to "{}"'.format(
bytes_path, compressed_path,
))
with open(bytes_path, 'rb') as f_in:
with gzip.open(compressed_path, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
logging.info('Removing "{}"'.format(bytes_path))
os.remove(bytes_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment