1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! A zero-dependency DEFLATE (RFC 1951), gzip (RFC 1952), and zlib
//! (RFC 1950) encoder and decoder.
//!
//! - `no_std` (requires only `alloc`)
//! - No `unsafe` code
//! - Sans-io: callers drive encoding and decoding via `feed` / `output` /
//! `advance`, with no I/O performed by the library itself
//! - WebSocket `permessage-deflate` (RFC 7692) support via
//! [`deflate::Encoder::sync_flush`] and [`deflate::Encoder::reset_history`]
//!
//! # Examples
//!
//! One-shot compression and decompression:
//!
//! ```
//! # fn main() -> noflate::Result<()> {
//! let input = b"Hello, DEFLATE!";
//! let compressed = noflate::deflate::compress(input)?;
//! let decompressed = noflate::deflate::decompress(&compressed)?;
//! assert_eq!(decompressed, input);
//! # Ok(())
//! # }
//! ```
//!
//! Streaming encoder:
//!
//! ```
//! # fn main() -> noflate::Result<()> {
//! let mut encoder = noflate::deflate::Encoder::new();
//! encoder.feed(b"Hello, ")?;
//! encoder.feed(b"world!")?;
//! encoder.finish()?;
//! let compressed = encoder.output().to_vec();
//! encoder.advance(compressed.len());
//! assert_eq!(
//! noflate::deflate::decompress(&compressed)?,
//! b"Hello, world!",
//! );
//! # Ok(())
//! # }
//! ```
//!
//! Streaming decoder:
//!
//! ```
//! # fn main() -> noflate::Result<()> {
//! # let compressed = noflate::deflate::compress(b"hello")?;
//! let mut decoder = noflate::deflate::Decoder::new();
//! decoder.feed(&compressed)?;
//! let out = decoder.output().to_vec();
//! decoder.advance(out.len());
//! assert!(decoder.is_finished());
//! assert_eq!(out, b"hello");
//! # Ok(())
//! # }
//! ```
//!
//! The [`gzip`] and [`zlib`] modules provide the same API shape for their
//! respective container formats.
//!
//! The crate performs no I/O itself, but the sans-io API plugs into
//! `std::io::Write` and `std::io::Read` with a small adapter: drain
//! [`deflate::Encoder::output`] into any `Write` sink, and top up
//! [`deflate::Decoder::feed`] from any `Read` source. See
//! `examples/io_bridge.rs` in the repository for a runnable
//! `DeflateWriter` / `DeflateReader` pair; the same pattern works
//! verbatim for the [`gzip`] and [`zlib`] streaming types.
//!
//! [`Format::detect`] identifies the format of a compressed stream:
//!
//! ```
//! # fn main() -> noflate::Result<()> {
//! let data = noflate::gzip::compress(b"hello")?;
//! assert_eq!(noflate::Format::detect(&data), Some(noflate::Format::Gzip));
//! # Ok(())
//! # }
//! ```
extern crate alloc;
extern crate std;
pub use ;
/// The detected compression format of a byte stream.