API Reference

flate2

DEFLATE, gzip, and zlib compression for Rust with multiple interchangeable backends.

Official Documentation ↗
CompatibilityThis documentation covers version v1.0. Check the official docs for the latest API surface.

Installation

cargocargo add flate2

Methods

flate2 provides read and write wrappers for gzip and zlib streams over any IO type.

Key Features

  • gzip, zlib, and raw deflate
  • Read and write adapters
  • Level configuration

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/flate2/latest/flate2/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:42.274Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

Which backend should I pick?
Default to the pure-Rust backend for portability; enable the zlib backend feature when you need its speed.
How do I stream large files?
Wrap the file reader or writer directly so compression happens in chunks without buffering the whole file.
What is the difference between gzip and zlib?
gzip carries a header and checksum and is used for files; zlib is a bare deflate stream often used inside protocols.