https://github.com/adumbidiot/lz-str-rs
A port of lz-string to Rust
https://github.com/adumbidiot/lz-str-rs
lz-str-rs lz-string lz-string-rs lzstring rust
Last synced: 7 months ago
JSON representation
A port of lz-string to Rust
- Host: GitHub
- URL: https://github.com/adumbidiot/lz-str-rs
- Owner: adumbidiot
- License: apache-2.0
- Created: 2019-04-06T23:44:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-16T09:05:28.000Z (almost 2 years ago)
- Last Synced: 2025-04-10T02:55:08.123Z (about 1 year ago)
- Topics: lz-str-rs, lz-string, lz-string-rs, lzstring, rust
- Language: Rust
- Homepage: https://adumbidiot.github.io/lz-str-rs/lz_str/
- Size: 1.46 MB
- Stars: 28
- Watchers: 1
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE.md
Awesome Lists containing this project
- awesome-list - lz-str-rs - string to Rust | adumbidiot | 9 | (Rust)
README
# lz-str-rs
[](https://crates.io/crates/lz-str)
[](https://docs.rs/lz-str)
[](./LICENSE-APACHE)

A port of [lz-string](https://github.com/pieroxy/lz-string) to Rust.
### Installing
Add the following to your `Cargo.toml` file:
```toml
[dependencies]
lz-str = "0.2.1"
```
## Getting Started
```rust
// The demonstrated functions correspond with `LZString.compress` and `LZString.decompress` from the JS version.
fn main() {
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);
}
```
See the [examples](https://github.com/adumbidiot/lz-str-rs/tree/master/examples) directory for more examples.
## Features
`rustc-hash`: This feature will replace some internal maps' hashers with rustc-hash,
boosting performance at the cost of not using a DOS-resistant hasher.
## Testing
```bash
cargo test
```
## Benching
```bash
cargo bench
```
## Bindings
* [WebAssembly](bindings/lz-str-wasm)
* [Python](bindings/lz-str-py)
## Authors
adumbidiot (Nathaniel Daniel)
## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
## Contributing
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.