PyDocs

Nav

Data Compression and Archiving

compress

gzip

function · Added in 3.2 (source)
  • compress(data, compresslevel=6, *, mtime=0)
Compress data in one shot and return the compressed string.

compresslevel sets the compression level in range of 0-9.
mtime can be used to set the modification time.
The modification time is set to 0 by default, for reproducibility.
Changed in 3.8, 3.11, 3.13, 3.14, 3.15
  • 3.8: Added the mtime parameter for reproducible output.
  • 3.11: Speed is improved by compressing all data at once instead of in a streamed fashion. Calls with mtime set to 0 are delegated to zlib.compress() for better speed. In this situation the output may contain a gzip header “OS” byte value other than 255 “unknown” as supplied by the underlying zlib implementation.
  • 3.13: The gzip header OS byte is guaranteed to be set to 255 when this function is used as was the case in 3.10 and earlier.
  • 3.14: The mtime parameter now defaults to 0 for reproducible output. For the previous behaviour of using the current time, pass None to mtime.
  • 3.15: The default compression level was reduced to 6 (down from 9). It is the default level used by most compression tools and a better tradeoff between speed and performance.
0 Examples
No examples for gzip/compress.
See Also
No see-alsos for gzip/compress
0 Notes
No notes for compress