Expand description
CramJam documentation of python exported functions for (de)compression of bytes
Although this documentation is built using Cargo/Rust toolchain, the examples and API represent the usable Python API
In general, the API follows cramjam.<<compression algorithm>>.compress
and cramjam.<<compression algorithm>>.decompress
as well as compress_into
/decompress_into
where it takes an input and output combination of any of the following:
numpy.array
(dtype=np.uint8)bytes
bytearray
cramjam.File
cramjam.Buffer
§Simple Python Example:
>>> data = b'some bytes here'
>>> compressed = cramjam.snappy.compress(data)
>>> decompressed = cramjam.snappy.decompress(compressed)
>>> assert bytes(data) == bytes(decompressed)
>>>
§Example of de/compressing into different types.
>>> import numpy as np
>>> from cramjam import snappy, Buffer
>>>
>>> data = np.frombuffer(b'some bytes here', dtype=np.uint8)
>>> data
array([115, 111, 109, 101, 32, 98, 121, 116, 101, 115, 32, 104, 101,
114, 101], dtype=uint8)
>>>
>>> compressed = Buffer()
>>> snappy.compress_into(data, compressed)
33 # 33 bytes written to compressed buffer
>>>
>>> compressed.tell() # Where is the buffer position?
33 # goodie!
>>>
>>> compressed.seek(0) # Go back to the start of the buffer so we can prepare to decompress
>>> decompressed = b'0' * len(data) # let's write to `bytes` as output
>>> decompressed
b'000000000000000'
>>>
>>> snappy.decompress_into(compressed, decompressed)
15 # 15 bytes written to decompressed
>>> decompressed
b'some bytes here'
Modules§
- brotli
- brotli de/compression interface
- deflate
- deflate de/compression interface
- exceptions
- cramjam specific Python exceptions
- gzip
- gzip de/compression interface
- io
- Module holds native Rust objects exposed to Python, or objects which wrap native Python objects to provide additional functionality or tighter integration with de/compression algorithms.
- lz4
- lz4 de/compression interface
- snappy
- snappy de/compression interface
- zstd
- zstd de/compression interface
Macros§
- generic
- Macro for generating the implementation of de/compression against a variant interface
- to_
py_ err - Macro to convert an error into a specific Python exception.
Enums§
- Bytes
Type - Any possible input/output to de/compression algorithms. Typically, as a Python user, you never have to worry about this object. It’s exposed here in the documentation to see what types are acceptable for de/compression functions.
Functions§
- PyInit_
cramjam ⚠ - This autogenerated function is called by the python interpreter when importing the module.