GithubHelp home page GithubHelp logo

adumbidiot / lz-str-rs Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 7.0 1.59 MB

A port of lz-string to Rust

Home Page: https://adumbidiot.github.io/lz-str-rs/lz_str/

License: Apache License 2.0

Rust 94.36% JavaScript 4.70% Makefile 0.47% Python 0.46%
lzstring rust lz-string-rs lz-str-rs lz-string

lz-str-rs's Introduction

lz-str-rs

crates.io Documentation MIT/Apache-2 licensed Rust

A port of lz-string to Rust.

Installing

Add the following to your Cargo.toml file:

[dependencies]
lz-str = "0.2.1"

Getting Started

// 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 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

cargo test

Benching

cargo bench

Bindings

Authors

adumbidiot (Nathaniel Daniel)

License

Licensed under either of

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.

lz-str-rs's People

Contributors

adumbidiot avatar dependabot-preview[bot] avatar dependabot[bot] avatar fxwiegand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lz-str-rs's Issues

How do I handle the error ?

image

expect() will cause the whole service shut down (but I don't want that), how do I handle it like this:

fn main() {
    let f = File::open("hello.txt");
    match f {
        Ok(file) => {
            println!("File opened successfully.");
        },
        Err(err) => {
            println!("Failed to open the file.");
        }
    }
}

// or
if err {
   ....
}

decompress return Option not Result:

image

why is compress_uri returning an option

compress returns a String but compress_uri returns an Option, even though the code always resolves to a Some and there are no obvious None cases that might appear in the future

any reason behind using an Option?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.