Crates.io | palmdoc-compression |
lib.rs | palmdoc-compression |
version | 0.3.1 |
source | src |
created_at | 2024-04-10 05:50:35.060117 |
updated_at | 2024-04-14 05:39:25.157533 |
description | Fast & safe implementation of PalmDoc/MOBI/AZW/Kindle flavored LZ77 |
homepage | |
repository | https://github.com/codetheweb/palmdoc-compression |
max_upload_size | |
id | 1203193 |
size | 62,685 |
This is a fast, safe, and correct implementation of PalmDoc-flavored LZ77 compression (primarily used by Amazon ebook formats). Compression is 300-400x faster than Calibre's implementation with a comparable compression ratio.
This crate also includes Calibre's version for comparison and usage if desired, gated behind the calibre
feature.
use palmdoc_compression::{compress, decompress};
let data = b"hello world";
let compressed = compress(data);
let decompressed = decompress(&compressed).unwrap();
assert_eq!(data, decompressed);
MOBI/AZW files are split into 4KB chunks, so benchmarks here also use 4KB chunks. Benchmarks were run on a M1 Max.
For a 4KB chunk of lorem ipsum text:
Decompression | Compression | |
---|---|---|
Calibre | 922 MiB/s | 252 KiB/s |
palmdoc-compression | 797 MiB/s | 109 MiB/s |
For a random 4KB chunk of War and Peace from Project Gutenberg:
Decompression | Compression | |
---|---|---|
Calibre | 1011 MiB/s | 336 KiB/s |
palmdoc-compression | 876 MiB/s | 103 MiB/s |
(Reproduce with cargo bench --features calibre
.)
Ratios calculated by compressing War and Peace from Project Gutenberg in 4KB chunks.
ratio, ⬇️ is better | |
---|---|
calibre | 0.56% (theoretical max) |
palmdoc-compression | 0.57% |
(Reproduce with cargo run --example ratios --release --features calibre
.)