#zlib #zlib-ng

sys libz-sys

Low-level bindings to the system libz library (also known as zlib)

36 stable releases

1.1.9 Apr 28, 2023
1.1.8 May 28, 2022
1.1.6 Apr 27, 2022
1.1.5 Mar 8, 2022
0.1.0 Nov 27, 2014

#20 in Compression

Download history 333979/week @ 2023-02-13 340130/week @ 2023-02-20 344644/week @ 2023-02-27 358074/week @ 2023-03-06 358329/week @ 2023-03-13 379930/week @ 2023-03-20 366040/week @ 2023-03-27 309874/week @ 2023-04-03 321887/week @ 2023-04-10 325749/week @ 2023-04-17 341020/week @ 2023-04-24 348104/week @ 2023-05-01 357874/week @ 2023-05-08 358369/week @ 2023-05-15 372579/week @ 2023-05-22 351797/week @ 2023-05-29

1,463,280 downloads per month
Used in 2,435 crates (63 directly)


50K SLoC

C 30K SLoC // 0.2% comments Visual Studio Project 14K SLoC Ada 1.5K SLoC // 0.2% comments Pascal 1K SLoC // 0.2% comments C# 879 SLoC // 0.4% comments Visual Studio Solution 655 SLoC C++ 599 SLoC // 0.2% comments Rust 495 SLoC // 0.1% comments Shell 491 SLoC // 0.2% comments GNU Style Assembly 246 SLoC // 0.5% comments Automake 34 SLoC


A common library for linking libz to rust programs (also known as zlib).


This also serves as the source for the libz-ng-sys crate, which builds zlib-ng natively (not in zlib-compat mode). See README-zng.md for details.

High-level API

This crate provides bindings to the raw low-level C API. For a higher-level safe API to work with DEFLATE, zlib, or gzip streams, see flate2. flate2 also supports alternative implementations, including slower but pure Rust implementations.


This crate supports building either the high-performance zlib-ng (in zlib-compat mode), or the widely available stock zlib.

By default, libz-sys uses stock zlib, primarily because doing so allows the use of a shared system zlib library if available.

Any application or library designed for zlib should work with zlib-ng in zlib-compat mode, as long as it doesn't make assumptions about the exact size or output of the deflated data (e.g. "compressing this data produces exactly this many bytes"), and as long as you don't also dynamically pull in a copy of stock zlib (which will produce conflicting symbols). Nonetheless, for maximum compatibility, every library crate in a build must opt into allowing zlib-ng; if any library crate in your dependency graph wants stock zlib, libz-sys will use stock zlib.

Library crates depending on libz-sys should use:

libz-sys = { version = "1.1.0", default-features = false, features = ["libc"] }

(Omit the libc feature if you don't require the corresponding functions.)

This allows higher-level crates depending on your library to opt into zlib-ng if desired.

Building zlib-ng requires cmake.

Crates that don't require compatibility with the zlib C API, and use zlib exclusively from Rust or support the zlib-ng native C API (prefixed with zng_) can use libz-ng-sys instead, which allows zlib and zlib-ng to coexist in the same program. See README-zng.md for details.


This project is licensed under either of

at your option.


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