| <!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="This crate provides an implementation of the Snappy compression format, as well as the framing format. The goal of Snappy is to provide reasonable compression at high speed. On a modern CPU, Snappy can compress data at about 300 MB/sec or more and can decompress data at about 800 MB/sec or more."><meta name="keywords" content="rust, rustlang, rust-lang, snap"><title>snap - 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">☰</button><a class="sidebar-logo" href="../snap/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="../snap/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate snap</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.2.5</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li><li><a href="#types">Type Definitions</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="#">snap</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/snap/lib.rs.html#1-118">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This crate provides an implementation of the |
| <a href="https://github.com/google/snappy/blob/master/format_description.txt">Snappy compression format</a>, |
| as well as the |
| <a href="https://github.com/google/snappy/blob/master/framing_format.txt">framing format</a>. |
| The goal of Snappy is to provide reasonable compression at high speed. On a |
| modern CPU, Snappy can compress data at about 300 MB/sec or more and can |
| decompress data at about 800 MB/sec or more.</p> |
| <h2 id="install"><a href="#install">Install</a></h2> |
| <p>To use this crate with |
| <a href="http://doc.crates.io/index.html">Cargo</a>, |
| simply add it as a dependency to your <code>Cargo.toml</code>:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code>[dependencies] |
| snap = <span class="string">"0.2"</span></code></pre></div> |
| <p>and add <code>extern crate snap;</code> to your crate root.</p> |
| <h2 id="overview"><a href="#overview">Overview</a></h2> |
| <p>This crate provides two ways to use Snappy. The first way is through the |
| <code>Reader</code> and <code>Writer</code> types, which implement the <code>std::io::Read</code> and |
| <code>std::io::Write</code> traits with the Snappy frame format. Unless you have a |
| specific reason to the contrary, you should only need to use these types. |
| Specifically, the Snappy frame format permits streaming compression or |
| decompression.</p> |
| <p>The second way is through the <code>Decoder</code> and <code>Encoder</code> types. These types |
| provide lower level control to the raw Snappy format, and don’t support a |
| streaming interface directly. You should only use these types if you know you |
| specifically need the Snappy raw format.</p> |
| <p>Finally, the <code>Error</code> type in this crate provides an exhaustive list of error |
| conditions that are probably useless in most circumstances. Therefore, |
| <code>From<snap::Error> for io::Error</code> is implemented in this crate, which will let |
| you automatically convert a Snappy error to an <code>std::io::Error</code> (when using |
| <code>try!</code>) with an appropriate error message to display to an end user.</p> |
| <h2 id="example-compress-data-on-stdin"><a href="#example-compress-data-on-stdin">Example: compress data on <code>stdin</code></a></h2> |
| <p>This program reads data from <code>stdin</code>, compresses it and emits it to <code>stdout</code>. |
| This example can be found in <code>examples/compress.rs</code>:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">extern crate </span>snap; |
| |
| <span class="kw">use </span>std::io; |
| |
| <span class="kw">fn </span>main() { |
| <span class="kw">let </span>stdin = io::stdin(); |
| <span class="kw">let </span>stdout = io::stdout(); |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>rdr = stdin.lock(); |
| <span class="comment">// Wrap the stdout writer in a Snappy writer. |
| </span><span class="kw">let </span><span class="kw-2">mut </span>wtr = snap::Writer::new(stdout.lock()); |
| io::copy(<span class="kw-2">&mut </span>rdr, <span class="kw-2">&mut </span>wtr).expect(<span class="string">"I/O operation failed"</span>); |
| }</code></pre></div> |
| <h2 id="example-decompress-data-on-stdin"><a href="#example-decompress-data-on-stdin">Example: decompress data on <code>stdin</code></a></h2> |
| <p>This program reads data from <code>stdin</code>, decompresses it and emits it to <code>stdout</code>. |
| This example can be found in <code>examples/decompress.rs</code>:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">extern crate </span>snap; |
| |
| <span class="kw">use </span>std::io; |
| |
| <span class="kw">fn </span>main() { |
| <span class="kw">let </span>stdin = io::stdin(); |
| <span class="kw">let </span>stdout = io::stdout(); |
| |
| <span class="comment">// Wrap the stdin reader in a Snappy reader. |
| </span><span class="kw">let </span><span class="kw-2">mut </span>rdr = snap::Reader::new(stdin.lock()); |
| <span class="kw">let </span><span class="kw-2">mut </span>wtr = stdout.lock(); |
| io::copy(<span class="kw-2">&mut </span>rdr, <span class="kw-2">&mut </span>wtr).expect(<span class="string">"I/O operation failed"</span>); |
| }</code></pre></div> |
| </div></details><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.Decoder.html" title="snap::Decoder struct">Decoder</a></div><div class="item-right docblock-short">Decoder is a raw decoder for decompressing bytes in the Snappy format.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Encoder.html" title="snap::Encoder struct">Encoder</a></div><div class="item-right docblock-short">Encoder is a raw encoder for compressing bytes in the Snappy format.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.IntoInnerError.html" title="snap::IntoInnerError struct">IntoInnerError</a></div><div class="item-right docblock-short"><code>IntoInnerError</code> occurs when consuming a <code>Writer</code> fails.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Reader.html" title="snap::Reader struct">Reader</a></div><div class="item-right docblock-short">A reader for decompressing a Snappy stream.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Writer.html" title="snap::Writer struct">Writer</a></div><div class="item-right docblock-short">A writer for compressing a Snappy 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.Error.html" title="snap::Error enum">Error</a></div><div class="item-right docblock-short">Error describes all the possible errors that may occur during Snappy |
| compression or decompression.</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.decompress_len.html" title="snap::decompress_len fn">decompress_len</a></div><div class="item-right docblock-short">Returns the decompressed size (in bytes) of the compressed bytes given.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.max_compress_len.html" title="snap::max_compress_len fn">max_compress_len</a></div><div class="item-right docblock-short">Returns the maximum compressed size given the uncompressed size.</div></div></div><h2 id="types" class="small-section-header"><a href="#types">Type Definitions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="type" href="type.Result.html" title="snap::Result type">Result</a></div><div class="item-right docblock-short">A convenient type alias for <code>Result<T, snap::Error></code>.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="snap" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |