#deflate #ram #string #gzip

compressed_string

String stored in memory in a compressed form, using the DEFLATE algorithm

1 stable release

1.0.0 Dec 30, 2018

#6 in #ram

Download history 4/week @ 2021-04-06 51/week @ 2021-04-13 8/week @ 2021-04-20 10/week @ 2021-04-27 9/week @ 2021-05-04 2/week @ 2021-05-11 68/week @ 2021-05-18 10/week @ 2021-05-25 2/week @ 2021-06-01 18/week @ 2021-06-08 10/week @ 2021-06-15 3/week @ 2021-06-22 9/week @ 2021-06-29 11/week @ 2021-07-06 2/week @ 2021-07-13 9/week @ 2021-07-20

71 downloads per month

CC0 license

6KB
79 lines

In-memory compressed String

If your application keeps many long strings in RAM, you can reduce its memory usage by compressing the strings.

Optionally, if with_serde feature is enabled, it can also be used to serialize and deserialize strings in binary formats in an already-compressed form.

use compressed_string::ComprString;

let raw = "It uses the deflate algorithm, which has a small header overhead, \
so it's suitable even for short-ish strings";

let compr = ComprString::new(raw);

assert_eq!(109, raw.len());
assert_eq!(84, compr.compressed_len());

println!("{}", compr);
let string = compr.to_string();

lib.rs:

use compressed_string::ComprString;

let raw = "It uses the deflate algorithm, which has a small header overhead, \
so it's suitable even for short-ish strings";

let compr = ComprString::new(raw);

assert_eq!(109, raw.len());
assert_eq!(84, compr.compressed_len());

println!("{}", compr);
let string = compr.to_string();

Dependencies

~250–550KB
~11K SLoC