Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DEFLATE, gzip, and zlib bindings for Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

rust-lang/flate2-rs

Crates.ioDocumentation

A streaming compression/decompression library DEFLATE-based streams in Rust.

This crate by default uses theminiz_oxide crate, a port ofminiz.c to pureRust. This crate also supports otherbackends, such as the widelyavailable zlib library or the high-performance zlib-ng library.

Supported formats:

  • deflate
  • zlib
  • gzip
# Cargo.toml[dependencies]flate2 ="1.0"

MSRV (Minimum Supported Rust Version) Policy

This crate supports the current and previous stable versions of the Rust compiler.For example, if the current stable is 1.80, this crate supports 1.80 and 1.79.

Other compiler versions may work, but failures may not be treated as aflate2 bug.

TheCargo.toml file specifies arust-version for which builds of the current versionpassed at some point. This value is indicative only, and may change at any time.

Therust-version is a best-effort measured value and is different to the MSRV. Therust-version can be incremented by a PR in order to pass tests, as long as the MSRVcontinues to hold. When therust-version increases, the next release should be a minorversion, to allow any affected users to pin to a previous minor version.

Compression

use std::io::prelude::*;use flate2::Compression;use flate2::write::ZlibEncoder;fnmain(){letmut e =ZlibEncoder::new(Vec::new(),Compression::default());    e.write_all(b"foo");    e.write_all(b"bar");let compressed_bytes = e.finish();}

Decompression

use std::io::prelude::*;use flate2::read::GzDecoder;fnmain(){letmut d =GzDecoder::new("...".as_bytes());letmut s =String::new();    d.read_to_string(&mut s).unwrap();println!("{}", s);}

Backends

The defaultminiz_oxide backend has the advantage of only using safe Rust.

If you want maximum performance while still benefiting from a Rustimplementation at the cost of someunsafe, you can usezlib-rs:

[dependencies]flate2 = {version ="1.0.17",features = ["zlib-rs"],default-features =false }

C backends

While zlib-rs isthe fastest overall,the zlib-ng C library can be slightly faster in certain cases:

[dependencies]flate2 = {version ="1.0.17",features = ["zlib-ng"],default-features =false }

Note that the"zlib-ng" feature works even if some other part of your crategraph depends on zlib.

However, if you're already using another C or Rust library that depends onzlib, and you want to avoid including both zlib and zlib-ng, you can use thatfor Rust code as well:

[dependencies]flate2 = {version ="1.0.17",features = ["zlib"],default-features =false }

Or, if you have C or Rust code that depends on zlib and you want to use zlib-ngvia libz-sys in zlib-compat mode, use:

[dependencies]flate2 = {version ="1.0.17",features = ["zlib-ng-compat"],default-features =false }

Note that when using the"zlib-ng-compat" feature, if any crate in yourdependency graph explicitly requests stock zlib, or uses libz-sys directlywithoutdefault-features = false, you'll get stock zlib rather than zlib-ng.Seethe libz-sysREADME for details.To avoid that, use the"zlib-ng" feature instead.

For compatibility with previous versions offlate2, the Cloudflare optimizedversion of zlib is available, via thecloudflare_zlib feature. It's not asfast as zlib-ng, but it's faster than stock zlib. It requires an x86-64 CPU withSSE 4.2 or ARM64 with NEON & CRC. It does not support 32-bit CPUs at all and isincompatible with mingw. For more information check thecratedocumentation. Note thatcloudflare_zlib will cause breakage if any other crate in your crate graphuses another version of zlib/libz.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in this project by you, as defined in the Apache-2.0 license,shall be dual licensed as above, without any additional terms or conditions.

About

DEFLATE, gzip, and zlib bindings for Rust

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Security policy

Stars

Watchers

Forks

Contributors99

Languages


[8]ページ先頭

©2009-2025 Movatter.jp