Expand description
A port of lz-string to Rust.
§Example
let data = "The quick brown fox jumps over the lazy dog";
// Compress the data. This cannot fail.
let compressed_data = lz_str::compress(data);
// Decompress the data.
// This may return `Option::None` if it fails.
// Make sure to do error-checking in a real application to prevent crashes!
let decompressed_data =
lz_str::decompress(compressed_data).expect("`compressed_data` is invalid");
// The decompressed_data should be the same as data, except encoded as UTF16.
// We undo that here.
// In a real application,
// you will want to do error checking to prevent users from causing crashes with invalid data.
let decompressed_data =
String::from_utf16(&decompressed_data).expect("`decompressed_data` is not valid UTF16");
assert!(data == decompressed_data);
§Passing and Recieving Data
The original library uses invalid UTF16 strings to represent data.
To maintain compatability, this library uses a Vec
of u16
s instead of Rust strings where applicable.
The IntoWideIter
trait exists to ease the passing of data into functions.
Most functions accept this generic parameter instead of a concrete type.
Look at this trait’s documentation to see what types this trait is implemented for.
Traits§
- A trait to make it easier to pass arguments to functions.
Functions§
- Compress a string into a
Vec<u16>
. - The internal function for compressing data.
- Compress a string into a
String
, which is valid base64. - Compress a string into a
String
, which can be safely used in a uri. - Compress a string into a
Vec<u8>
. - Compress a string as a valid
String
. - Decompress a string into a
Vec<u16>
. The result contains possibly invalid UTF16. - Decompress a
&str
compressed withcrate::compress_to_base64
. - Decompress a
&str
compressed withcrate::compress_to_encoded_uri_component
. - Decompress a byte slice compressed with
crate::compress_to_uint8_array
. - Decompress a
&str
compressed withcrate::compress_to_utf16
. - The internal decompress function.