blob: 73e1a79c036b81e0ec0c6c769188ac649d328c8a [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A DEFLATE-based stream compression/decompression library"><meta name="keywords" content="rust, rustlang, rust-lang, flate2"><title>flate2 - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../flate2/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../flate2/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate flate2</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 1.0.26</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">flate2</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/flate2/lib.rs.html#1-206">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A DEFLATE-based stream compression/decompression library</p>
<p>This library provides support for compression and decompression of
DEFLATE-based streams:</p>
<ul>
<li>the DEFLATE format itself</li>
<li>the zlib format</li>
<li>gzip</li>
</ul>
<p>These three formats are all closely related and largely only differ in their
headers/footers. This crate has three types in each submodule for dealing
with these three formats.</p>
<h2 id="implementation"><a href="#implementation">Implementation</a></h2>
<p>In addition to supporting three formats, this crate supports several different
backends, controlled through this crate’s features:</p>
<ul>
<li>
<p><code>default</code>, or <code>rust_backend</code> - this implementation uses the <code>miniz_oxide</code>
crate which is a port of <code>miniz.c</code> (below) to Rust. This feature does not
require a C compiler and only requires Rust code.</p>
</li>
<li>
<p><code>zlib</code> - this feature will enable linking against the <code>libz</code> library, typically found on most
Linux systems by default. If the library isn’t found to already be on the system it will be
compiled from source (this is a C library).</p>
</li>
</ul>
<p>There’s various tradeoffs associated with each implementation, but in general you probably
won’t have to tweak the defaults. The default choice is selected to avoid the need for a C
compiler at build time. <code>zlib-ng-compat</code> is useful if you’re using zlib for compatibility but
want performance via zlib-ng’s zlib-compat mode. <code>zlib</code> is useful if something else in your
dependencies links the original zlib so you cannot use zlib-ng-compat. The compression ratios
and performance of each of these feature should be roughly comparable, but you’ll likely want
to run your own tests if you’re curious about the performance.</p>
<h2 id="organization"><a href="#organization">Organization</a></h2>
<p>This crate consists mainly of three modules, <a href="read/index.html"><code>read</code></a>, <a href="write/index.html"><code>write</code></a>, and
<a href="bufread/index.html"><code>bufread</code></a>. Each module contains a number of types used to encode and
decode various streams of data.</p>
<p>All types in the <a href="write/index.html"><code>write</code></a> module work on instances of <a href="https://doc.rust-lang.org/std/io/trait.Write.html"><code>Write</code></a>,
whereas all types in the <a href="read/index.html"><code>read</code></a> module work on instances of
<a href="https://doc.rust-lang.org/std/io/trait.Read.html"><code>Read</code></a> and <a href="bufread/index.html"><code>bufread</code></a> works with <a href="https://doc.rust-lang.org/std/io/trait.BufRead.html"><code>BufRead</code></a>. If you
are decoding directly from a <code>&amp;[u8]</code>, use the <a href="bufread/index.html"><code>bufread</code></a> types.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>flate2::write::GzEncoder;
<span class="kw">use </span>flate2::Compression;
<span class="kw">use </span>std::io;
<span class="kw">use </span>std::io::prelude::<span class="kw-2">*</span>;
<span class="kw">let </span><span class="kw-2">mut </span>encoder = GzEncoder::new(Vec::new(), Compression::default());
encoder.write_all(<span class="string">b&quot;Example&quot;</span>)<span class="question-mark">?</span>;</code></pre></div>
<p>Other various types are provided at the top-level of the crate for
management and dealing with encoders/decoders. Also note that types which
operate over a specific trait often implement the mirroring trait as well.
For example a <code>flate2::read::DeflateDecoder&lt;T&gt;</code> <em>also</em> implements the
<code>Write</code> trait if <code>T: Write</code>. That is, the “dual trait” is forwarded directly
to the underlying object if available.</p>
</div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="bufread/index.html" title="flate2::bufread mod">bufread</a></div><div class="item-right docblock-short">Types which operate over <a href="https://doc.rust-lang.org/std/io/trait.BufRead.html"><code>BufRead</code></a> streams, both encoders and decoders for
various formats.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="read/index.html" title="flate2::read mod">read</a></div><div class="item-right docblock-short">Types which operate over <a href="https://doc.rust-lang.org/std/io/trait.Read.html"><code>Read</code></a> streams, both encoders and decoders for
various formats.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="write/index.html" title="flate2::write mod">write</a></div><div class="item-right docblock-short">Types which operate over <a href="https://doc.rust-lang.org/std/io/trait.Write.html"><code>Write</code></a> streams, both encoders and decoders for
various formats.</div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Compress.html" title="flate2::Compress struct">Compress</a></div><div class="item-right docblock-short">Raw in-memory compression stream for blocks of data.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.CompressError.html" title="flate2::CompressError struct">CompressError</a></div><div class="item-right docblock-short">Error returned when a compression object is used incorrectly or otherwise
generates an error.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Compression.html" title="flate2::Compression struct">Compression</a></div><div class="item-right docblock-short">When compressing data, the compression level can be specified by a value in
this enum.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Crc.html" title="flate2::Crc struct">Crc</a></div><div class="item-right docblock-short">The CRC calculated by a <a href="struct.CrcReader.html"><code>CrcReader</code></a>.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.CrcReader.html" title="flate2::CrcReader struct">CrcReader</a></div><div class="item-right docblock-short">A wrapper around a <a href="https://doc.rust-lang.org/std/io/trait.Read.html"><code>Read</code></a> that calculates the CRC.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.CrcWriter.html" title="flate2::CrcWriter struct">CrcWriter</a></div><div class="item-right docblock-short">A wrapper around a <a href="https://doc.rust-lang.org/std/io/trait.Write.html"><code>Write</code></a> that calculates the CRC.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Decompress.html" title="flate2::Decompress struct">Decompress</a></div><div class="item-right docblock-short">Raw in-memory decompression stream for blocks of data.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DecompressError.html" title="flate2::DecompressError struct">DecompressError</a></div><div class="item-right docblock-short">Error returned when a decompression object finds that the input stream of
bytes was not a valid input stream of bytes.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.GzBuilder.html" title="flate2::GzBuilder struct">GzBuilder</a></div><div class="item-right docblock-short">A builder structure to create a new gzip Encoder.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.GzHeader.html" title="flate2::GzHeader struct">GzHeader</a></div><div class="item-right docblock-short">A structure representing the header of a gzip stream.</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.FlushCompress.html" title="flate2::FlushCompress enum">FlushCompress</a></div><div class="item-right docblock-short">Values which indicate the form of flushing to be used when compressing
in-memory data.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.FlushDecompress.html" title="flate2::FlushDecompress enum">FlushDecompress</a></div><div class="item-right docblock-short">Values which indicate the form of flushing to be used when
decompressing in-memory data.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.Status.html" title="flate2::Status enum">Status</a></div><div class="item-right docblock-short">Possible status results of compressing some data or successfully
decompressing a block of data.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="flate2" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>