- Notifications
You must be signed in to change notification settings - Fork180
DEFLATE, gzip, and zlib bindings for Rust
License
Apache-2.0, MIT licenses found
Licenses found
rust-lang/flate2-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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"
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.
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();}
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);}
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 }
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.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE orhttps://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT orhttps://opensource.org/licenses/MIT)
at your option.
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
Security policy
Uh oh!
There was an error while loading.Please reload this page.