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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! Safe, clean-room LZVN encoding and decoding primitives.
//!
//! The crate currently provides safe Rust support for raw LZVN streams and
//! Apple wrappers such as `bvxn` and `decmpfs`, with no `unsafe` code.
pub use ;
pub use ;
pub use ;
/// Encode bytes as a raw LZVN stream.
///
/// The returned stream includes the padded 8-byte end-of-stream marker emitted
/// by Apple-compatible encoders.
///
/// # Examples
///
/// ```rust
/// let encoded = lzvn::encode_raw(b"hello");
/// let decoded = lzvn::decode_raw(&encoded, 5)?;
///
/// assert_eq!(decoded, b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Decode a raw LZVN stream into a newly allocated buffer.
///
/// The caller supplies the expected decoded size because raw LZVN streams do
/// not carry it on their own.
///
/// # Examples
///
/// ```rust
/// let encoded = [
/// 0xe5, b'h', b'e', b'l', b'l', b'o',
/// 0x06, 0, 0, 0, 0, 0, 0, 0,
/// ];
///
/// let decoded = lzvn::decode_raw(&encoded, 5)?;
/// assert_eq!(decoded, b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Decode a raw LZVN stream into an existing output buffer.
///
/// Returns the number of bytes written before the end-of-stream marker.
///
/// # Examples
///
/// ```rust
/// let encoded = [
/// 0xe5, b'h', b'e', b'l', b'l', b'o',
/// 0x06, 0, 0, 0, 0, 0, 0, 0,
/// ];
/// let mut decoded = [0_u8; 5];
///
/// let written = lzvn::decode_raw_into(&encoded, &mut decoded)?;
/// assert_eq!(written, 5);
/// assert_eq!(&decoded[..written], b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Encode bytes as an Apple `decmpfs` LZVN wrapper.
///
/// Small payloads are stored inline in the xattr and larger payloads are
/// stored in a resource fork.
///
/// # Examples
///
/// ```rust
/// let encoded = lzvn::encode_decmpfs(b"hello")?;
/// let decoded = lzvn::decode_decmpfs(&encoded.xattr, encoded.resource_fork.as_deref())?;
///
/// assert_eq!(decoded, b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Decode an Apple `decmpfs` wrapper into a newly allocated buffer.
///
/// # Examples
///
/// ```rust
/// let encoded = lzvn::encode_decmpfs(b"hello")?;
/// let decoded = lzvn::decode_decmpfs(&encoded.xattr, encoded.resource_fork.as_deref())?;
///
/// assert_eq!(decoded, b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Decode an Apple `decmpfs` wrapper into an existing output buffer.
/// Encode bytes as an Apple `bvxn` block.
///
/// # Examples
///
/// ```rust
/// let encoded = lzvn::encode_bvxn(b"hello")?;
/// let decoded = lzvn::decode_bvxn(&encoded)?;
///
/// assert_eq!(decoded, b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Decode an Apple `bvxn` block into a newly allocated buffer.
///
/// # Examples
///
/// ```rust
/// let encoded = [
/// b'b', b'v', b'x', b'n',
/// 0x05, 0x00, 0x00, 0x00,
/// 0x0e, 0x00, 0x00, 0x00,
/// 0xe5, b'h', b'e', b'l', b'l', b'o',
/// 0x06, 0, 0, 0, 0, 0, 0, 0,
/// ];
///
/// let decoded = lzvn::decode_bvxn(&encoded)?;
/// assert_eq!(decoded, b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
/// Decode an Apple `bvxn` block into an existing output buffer.
///
/// Returns the number of bytes written.
///
/// # Examples
///
/// ```rust
/// let encoded = [
/// b'b', b'v', b'x', b'n',
/// 0x05, 0x00, 0x00, 0x00,
/// 0x0e, 0x00, 0x00, 0x00,
/// 0xe5, b'h', b'e', b'l', b'l', b'o',
/// 0x06, 0, 0, 0, 0, 0, 0, 0,
/// ];
/// let mut decoded = [0_u8; 5];
///
/// let written = lzvn::decode_bvxn_into(&encoded, &mut decoded)?;
/// assert_eq!(written, 5);
/// assert_eq!(&decoded[..written], b"hello");
/// # Ok::<(), lzvn::Error>(())
/// ```
pub use ;