#zlib #zlib-ng #bindings #low-level #programs #libz #system

sys libz-sys

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

43 stable releases

1.1.16 Mar 21, 2024
1.1.12 Jul 26, 2023
1.1.8 May 28, 2022
1.1.5 Mar 8, 2022
0.1.0 Nov 27, 2014

#15 in Compression

Download history 580916/week @ 2024-01-05 560452/week @ 2024-01-12 566234/week @ 2024-01-19 557433/week @ 2024-01-26 544515/week @ 2024-02-02 587769/week @ 2024-02-09 527368/week @ 2024-02-16 567430/week @ 2024-02-23 567372/week @ 2024-03-01 555822/week @ 2024-03-08 580224/week @ 2024-03-15 620926/week @ 2024-03-22 610847/week @ 2024-03-29 590343/week @ 2024-04-05 601987/week @ 2024-04-12 507493/week @ 2024-04-19

2,421,186 downloads per month
Used in 3,010 crates (86 directly)

MIT/Apache

4MB
56K SLoC

C 29K SLoC // 0.2% comments Visual Studio Project 17K SLoC C++ 3.5K SLoC // 0.1% comments Ada 1.5K SLoC // 0.2% comments Pascal 1K SLoC // 0.2% comments C# 879 SLoC // 0.4% comments Visual Studio Solution 856 SLoC Rust 585 SLoC // 0.1% comments Bitbake 527 SLoC Shell 459 SLoC // 0.2% comments GNU Style Assembly 246 SLoC // 0.5% comments Automake 34 SLoC VBScript 12 SLoC Poke 1 SLoC

Contains (obscure autoconf code, 1KB) src/zlib/contrib/minizip/configure.ac

libz-sys

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

Documentation

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.

zlib-ng

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", 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.

Minimum Supported Rust Version (MSRV) Policy

This crate uses the same MSRV policy as the flate2 crate: This crate supports the current and previous stable versions of Rust. Older versions of Rust may work, but we don't guarantee these will continue to work.

License

This project is licensed under either of

at your option.

Contribution

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.

Dependencies