|
| 1 | +use crate::deflate::DeflateConfig; |
1 | 2 | use crate::inflate::InflateConfig; |
2 | 3 | use crate::ReturnCode; |
3 | 4 | pub use crate::{DeflateFlush, InflateFlush}; |
@@ -85,8 +86,18 @@ impl Inflate { |
85 | 86 | } |
86 | 87 |
|
87 | 88 | /// Create a new instance. Note that it allocates in various ways and thus should be re-used. |
| 89 | + /// |
| 90 | + /// The `window_bits` must be in the range `8..=15`, with `15` being most common. |
88 | 91 | pub fn new(zlib_header: bool, window_bits: u8) -> Self { |
89 | | - Self(crate::inflate::InflateStream::new(zlib_header, window_bits)) |
| 92 | + let config = InflateConfig { |
| 93 | + window_bits: if zlib_header { |
| 94 | + i32::from(window_bits) |
| 95 | + } else { |
| 96 | + -i32::from(window_bits) |
| 97 | + }, |
| 98 | + }; |
| 99 | + |
| 100 | + Self(crate::inflate::InflateStream::new(config)) |
90 | 101 | } |
91 | 102 |
|
92 | 103 | /// Reset the state to allow handling a new stream. |
@@ -203,12 +214,20 @@ impl Deflate { |
203 | 214 | } |
204 | 215 |
|
205 | 216 | /// Create a new instance - this allocates so should be done with care. |
| 217 | + /// |
| 218 | + /// The `window_bits` must be in the range `8..=15`, with `15` being most common. |
206 | 219 | pub fn new(level: i32, zlib_header: bool, window_bits: u8) -> Self { |
207 | | - Self(crate::deflate::DeflateStream::new( |
| 220 | + let config = DeflateConfig { |
| 221 | + window_bits: if zlib_header { |
| 222 | + i32::from(window_bits) |
| 223 | + } else { |
| 224 | + -i32::from(window_bits) |
| 225 | + }, |
208 | 226 | level, |
209 | | - zlib_header, |
210 | | - window_bits, |
211 | | - )) |
| 227 | + ..DeflateConfig::default() |
| 228 | + }; |
| 229 | + |
| 230 | + Self(crate::deflate::DeflateStream::new(config)) |
212 | 231 | } |
213 | 232 |
|
214 | 233 | /// Prepare the instance for a new stream. |
|
0 commit comments