Atom

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

Atom
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.

Atom
use archive
use binary
compressed = archive.compress('Atom')
print(binary.text(archive.decompress(compressed)))
Output
Atom

The round trip recovers the input text.

Compress an existing byte buffer

Packed data can be compressed without treating it as text.

Atom
use archive
use binary
source = binary.unhex('00ff')
compressed = archive.compress(source)
print(binary.hex(archive.decompress(compressed)))
Output
00ff

The two original bytes are recovered, including ff.