Skip to content

Instantly share code, notes, and snippets.

@en0
Created August 26, 2021 20:25
Show Gist options
  • Save en0/d4702bcec798a7e953d0bd2b808ec5f5 to your computer and use it in GitHub Desktop.
Save en0/d4702bcec798a7e953d0bd2b808ec5f5 to your computer and use it in GitHub Desktop.
gzip with zlib
import zlib
compressor = zlib.compressobj(method=zlib.DEFLATED, wbits=zlib.MAX_WBITS | 16)
with open('output.txt', 'wb') as fd:
for i in range(10000):
fd.write(compressor.compress(f"Line number {i}\n".encode('utf-8')))
fd.write(compressor.flush())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment