archive.compress()
Produces a zlib stream.
Signature
archive.compress(data[, level])
Parameters
Text or packed bytes, optional signed compression level 0 through 9, default miniz's default level.
Returns
Packed u8 stream.
Behavior
Reads its input without modification.
Errors
Oversized input or compression failure.
Example
use archive
use binary
assert(binary.text(archive.decompress(archive.compress('Atom'))) == 'Atom')
Compress and recover text
Compression yields bytes. Decode them as text only after decompression.
use archive
use binary
compressed = archive.compress('Atom')
print(binary.text(archive.decompress(compressed)))
Atom
The round trip recovers the input text.
Compress an existing byte buffer
Packed data can be compressed without treating it as text.
use archive
use binary
source = binary.unhex('00ff')
compressed = archive.compress(source)
print(binary.hex(archive.decompress(compressed)))
00ff
The two original bytes are recovered, including ff.