cramjam

API Documentation
Install (Python)
pip install --upgrade cramjam # Requires no Python or system dependencies!
Install (JavaScript / TypeScript)
npm install cramjam
CLI
A CLI interface is available as cramjam-cli
libcramjam
A Rust crate and C friendly library available at libcramjam
Extremely thin and easy-to-install Python bindings to de/compression algorithms in Rust.
Allows for using algorithms such as Snappy, without any system or other python dependencies.
Benchmarks
Some basic benchmarks are available in the benchmarks directory
Available algorithms:
Experimental (Requires build from source enabling each feature):
All available for use as:
>>> import cramjam
>>> import numpy as np
>>> compressed = cramjam.snappy.compress(b"bytes here")
>>> decompressed = cramjam.snappy.decompress(compressed)
>>> decompressed
cramjam.Buffer(len=10)
>>> bytes(decompressed)
b"bytes here"
>>> np.frombuffer(decompressed, dtype=np.uint8)
array([ 98, 121, 116, 101, 115, 32, 104, 101, 114, 101], dtype=uint8)
Where the API is cramjam.<compression-variant>.compress/decompress and accepts
bytes/bytearray/numpy.array/cramjam.File/cramjam.Buffer / memoryview objects.
de/compress_into
Additionally, all variants support decompress_into and compress_into.
Ex.
>>> 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
>>>
>>> compressed.tell()
33
>>>
>>> compressed.seek(0)
>>> decompressed = b'0' * len(data)
>>> decompressed
b'000000000000000'
>>>
>>> snappy.decompress_into(compressed, decompressed)
15
>>> decompressed
b'some bytes here'
TypeScript:
import {Compress, Decompress} from 'cramjam';
const decoder = new TextDecoder();
const encoder = new TextEncoder();
const str = 'hello, world';
const encoded = encoder.encode(str);
const compressed = Compress.brotli(encoded);
const decompressed = Decompress.brotli(compressed);
const decoded = decoder.decode(decompressed);