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
//! Compress and decompress data in bulk.
//!
//! These methods process all the input data at once.
//! It is therefore best used with relatively small blocks
//! (like small network packets).
pub use Compressor;
pub use Decompressor;
use io;
/// Compresses a single block of data to the given destination buffer.
///
/// Returns the number of bytes written, or an error if something happened
/// (for instance if the destination buffer was too small).
///
/// [`crate::compress_bound()`] says how large the destination might need to
/// be. Passing a `Vec` instead of a slice works too, and then it is the
/// `Vec`'s *capacity* that bounds the output - so `reserve` what you need
/// rather than `resize`, since the bytes do not have to be initialized.
///
/// A level of `0` uses zstd's default (currently `3`).
/// Compresses a block of data and returns the compressed result.
///
/// A level of `0` uses zstd's default (currently `3`).
/// Decompress a single block of data to the given destination buffer.
///
/// Returns the number of bytes written, or an error if something happened
/// (for instance if the destination buffer was too small).
///
/// [`crate::decompressed_size()`] says how big the result will be, when the
/// frame records it - there is no need to store the size alongside the data
/// yourself. Passing a `Vec` instead of a slice works too, and then it is the
/// `Vec`'s *capacity* that bounds the output, so `reserve` what you need
/// rather than `resize`.
/// Decompresses a block of data and returns the decompressed result.
///
/// The decompressed data should be at most `capacity` bytes, or an error will
/// be returned - so `capacity` is the most you are willing to allocate for
/// this, not a guess that has to be right. When the frame records its size,
/// only that much is allocated however large a `capacity` you allow.
///
/// [`crate::decompressed_size()`] gives you that size up front, if you would
/// rather decide for yourself.