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
//! Raw DEFLATE (RFC 1951).
//!
//! Tier 1 is one call each way; [`Inflater`] and [`Deflater`] are the
//! streaming engines underneath.
//! Raw DEFLATE has no header and no checksum: use it where the container
//! carries those (WebSocket permessage-deflate, zip entries). For HTTP's
//! `deflate` content coding, which is zlib framing, use `zlib` (0.5).
//!
//! ```
//! use compress_lib::deflate;
//!
//! let packed = deflate::compress(b"hello, hello, hello");
//! assert_eq!(deflate::decompress(&packed)?, b"hello, hello, hello");
//! # Ok::<(), compress_lib::Error>(())
//! ```
pub
use Vec;
pub use ;
pub use crateInflater;
pub use crate;
use crate::;
/// Compresses `data` into a complete raw DEFLATE stream at level 6.
///
/// # Examples
///
/// ```
/// use compress_lib::deflate;
///
/// let packed = deflate::compress(&[b'a'; 1000]);
/// assert!(packed.len() < 20);
/// assert_eq!(deflate::decompress(&packed)?, vec![b'a'; 1000]);
/// # Ok::<(), compress_lib::Error>(())
/// ```
/// Compresses `data` into a complete raw DEFLATE stream at `level`.
///
/// Allocation failure aborts, as for any `Vec`; use [`Deflater`] with a
/// caller-owned buffer to control memory.
///
/// # Examples
///
/// ```
/// use compress_lib::{Level, deflate};
///
/// let data = b"the quick brown fox jumps over the lazy dog, the quick brown fox";
/// let fast = deflate::compress_with(data, Level::FAST);
/// let stored = deflate::compress_with(data, Level::NONE);
/// assert!(fast.len() < stored.len());
/// assert_eq!(deflate::decompress(&stored)?, data);
/// # Ok::<(), compress_lib::Error>(())
/// ```
/// Decompresses a complete raw DEFLATE stream with the default [`Limits`]
/// (64 MiB of output at most).
///
/// # Errors
///
/// Any decoding error; `UnexpectedEnd` if the stream is truncated,
/// `TrailingData` if bytes follow its end, `OutputLimit` past 64 MiB.
///
/// # Examples
///
/// ```
/// use compress_lib::{ErrorKind, deflate};
///
/// assert_eq!(deflate::decompress(&[0x03, 0x00])?, b"");
/// let err = deflate::decompress(&[0x03, 0x00, 0xFF]).unwrap_err();
/// assert_eq!(err.kind(), ErrorKind::TrailingData);
/// # Ok::<(), compress_lib::Error>(())
/// ```
/// Decompresses a complete raw DEFLATE stream with the given limits.
///
/// # Errors
///
/// As [`decompress`], with the caps of `limits`.
///
/// # Examples
///
/// ```
/// use compress_lib::{ErrorKind, Limits, deflate};
///
/// // 1,000 zero bytes, compressed.
/// let packed = [0x63, 0x60, 0x18, 0x05, 0xA3, 0x60, 0x14, 0x0C, 0x77, 0x00, 0x00];
/// assert_eq!(deflate::decompress(&packed)?.len(), 1000);
/// let tight = Limits::new().with_max_output(999);
/// assert_eq!(deflate::decompress_with(&packed, tight).unwrap_err().kind(), ErrorKind::OutputLimit);
/// # Ok::<(), compress_lib::Error>(())
/// ```