One-Shot APIs¶
compress()¶
- zstandard.compress(data: Buffer, level: int = 3) bytes¶
Compress source data using the zstd compression format.
This performs one-shot compression using basic/default compression settings.
This method is provided for convenience and is equivalent to calling
ZstdCompressor(level=level).compress(data).If you find yourself calling this function in a tight loop, performance will be greater if you construct a single
ZstdCompressorand repeatedly callcompress()on it.
decompress()¶
- zstandard.decompress(data: Buffer, max_output_size: int = 0) bytes¶
Decompress a zstd frame into its original data.
This performs one-shot decompression using basic/default compression settings.
This method is provided for convenience and is equivalent to calling
ZstdDecompressor().decompress(data, max_output_size=max_output_size).If you find yourself calling this function in a tight loop, performance will be greater if you construct a single
ZstdDecompressorand repeatedly calldecompress()on it.
open()¶
- zstandard.open(filename, mode='rb', cctx=None, dctx=None, encoding=None, errors=None, newline=None, closefd=None)¶
Create a file object with zstd (de)compression.
The object returned from this function will be a
ZstdDecompressionReaderif opened for reading in binary mode, aZstdCompressionWriterif opened for writing in binary mode, or anio.TextIOWrapperif opened for reading or writing in text mode.- Parameters:
filename –
bytes,str, oros.PathLikedefining a file to open or a file object (with aread()orwrite()method).mode –
strFile open mode. Accepts any of the open modes recognized byopen().cctx –
ZstdCompressorto use for compression. If not specified and file is opened for writing, the defaultZstdCompressorwill be used.dctx –
ZstdDecompressorto use for decompression. If not specified and file is opened for reading, the defaultZstdDecompressorwill be used.encoding –
strthat defines text encoding to use when file is opened in text mode.errors –
strdefining text encoding error handling mode.newline –
strdefining newline to use in text mode.closefd –
boolwhether to close the file when the returned object is closed.Only used if a file object is passed. If a filename is specified, the opened file is always closed when the returned object is closed.