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
//! Raw DEFLATE (RFC 1951) compression and decompression.
//!
//! # Compression
//!
//! [`compress`] writes the bytes zlib-ng 2.3 writes: its parsers (one
//! fixed-code block at level 1, greedy parsing at level 2, its "medium"
//! parsing with a look-ahead match at levels 3 to 6, lazy parsing at 7 to
//! 9), its match finder and hashes, and zlib's block splitting and
//! Huffman codes, ported step for step. [`compress_with`] also takes
//! zlib's strategy and memory level ([`Options`]). Level 0 writes stored
//! blocks only.
//!
//! # Decompression
//!
//! [`decompress`] and friends decode with lookup tables and validate the
//! stream as strictly as zlib: malformed input yields an [`InflateError`],
//! never a panic. A size limit guards against decompression bombs.
//!
//! ```
//! use pltrs_codec::{deflate, CompressionLevel};
//!
//! let text = b"to be or not to be, that is the question; to be or not to be";
//! let packed = deflate::compress(text, CompressionLevel::DEFAULT)?;
//! assert!(packed.len() < text.len());
//! assert_eq!(deflate::decompress(&packed)?, text);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub
pub
pub
pub
pub use ;
pub use ;
pub use ;
use OutOfMemory;
use Wrap;
/// Compresses `data` into a new raw DEFLATE stream at `level`.
///
/// # Errors
///
/// When the memory for the output cannot be allocated.
/// Compresses `data` into a new raw DEFLATE stream as zlib-ng does with
/// `options`.
///
/// # Errors
///
/// When the memory for the compressor or the output cannot be allocated.
/// Appends the raw DEFLATE compression of `data` at `level` to `out`.
///
/// # Errors
///
/// When the memory for the compressor or the output cannot be allocated
/// (what was written of it stays in `out`).
/// Decompresses the raw DEFLATE stream at the start of `input`.
///
/// Bytes after the end of the final block are ignored; use
/// [`decompress_into`] to learn how many input bytes the stream occupied.
/// Like [`decompress`], but fails with
/// [`InflateError::OutputLimitExceeded`] instead of producing more than
/// `limit` bytes.
/// Decompresses the raw DEFLATE stream at the start of `input`, appending at
/// most `limit` bytes to `out`, and returns the number of input bytes the
/// stream occupied.
///
/// Back-references cannot reach into data that was already in `out`. On
/// error, `out` may hold part of the decompressed data; in particular, on
/// [`InflateError::OutputLimitExceeded`] exactly the first `limit` bytes
/// have been appended.