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
#![allow(warnings)]
#![forbid(unsafe_code)]
#![cfg_attr(any(has_alloc, feature = "rustc-dep-of-std"), no_std)]
#[cfg(any(has_alloc, feature = "rustc-dep-of-std"))]
extern crate alloc;
#[cfg(all(not(has_alloc), not(feature = "rustc-dep-of-std")))]
use std as alloc;
#[cfg(test)]
extern crate std;
pub mod deflate;
pub mod inflate;
mod shared;
pub use crate::shared::update_adler32 as mz_adler32_oxide;
pub use crate::shared::{MZ_ADLER32_INIT, MZ_DEFAULT_WINDOW_BITS};
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MZFlush {
None = 0,
Partial = 1,
Sync = 2,
Full = 3,
Finish = 4,
Block = 5,
}
impl MZFlush {
pub fn new(flush: i32) -> Result<Self, MZError> {
match flush {
0 => Ok(MZFlush::None),
1 | 2 => Ok(MZFlush::Sync),
3 => Ok(MZFlush::Full),
4 => Ok(MZFlush::Finish),
_ => Err(MZError::Param),
}
}
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MZStatus {
Ok = 0,
StreamEnd = 1,
NeedDict = 2,
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum MZError {
ErrNo = -1,
Stream = -2,
Data = -3,
Mem = -4,
Buf = -5,
Version = -6,
Param = -10_000,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DataFormat {
Zlib,
Raw,
}
impl DataFormat {
pub(crate) fn from_window_bits(window_bits: i32) -> DataFormat {
if window_bits > 0 {
DataFormat::Zlib
} else {
DataFormat::Raw
}
}
pub(crate) fn to_window_bits(self) -> i32 {
match self {
DataFormat::Zlib => shared::MZ_DEFAULT_WINDOW_BITS,
DataFormat::Raw => -shared::MZ_DEFAULT_WINDOW_BITS,
}
}
}
pub type MZResult = Result<MZStatus, MZError>;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct StreamResult {
pub bytes_consumed: usize,
pub bytes_written: usize,
pub status: MZResult,
}
impl StreamResult {
#[inline]
pub(crate) fn error(error: MZError) -> StreamResult {
StreamResult {
bytes_consumed: 0,
bytes_written: 0,
status: Err(error),
}
}
}
impl core::convert::From<StreamResult> for MZResult {
fn from(res: StreamResult) -> Self {
res.status
}
}
impl core::convert::From<&StreamResult> for MZResult {
fn from(res: &StreamResult) -> Self {
res.status
}
}