Skip to content

Commit 320d268

Browse files
committed
expose set_level
1 parent d2ab618 commit 320d268

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

zlib-rs/src/stable.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,25 @@ impl Deflate {
279279
other => unreachable!("set_dictionary does not return {other:?}"),
280280
}
281281
}
282+
283+
/// Dynamically updates the compression level.
284+
///
285+
/// This can be used to switch between compression levels for different
286+
/// kinds of data, or it can be used in conjunction with a call to [`Deflate::reset`]
287+
/// to reuse the compressor.
288+
///
289+
/// This may return an error if there wasn't enough output space to complete
290+
/// the compression of the available input data before changing the
291+
/// compression level. Flushing the stream before calling this method
292+
/// ensures that the function will succeed on the first call.
293+
pub fn set_level(&mut self, level: i32) -> Result<Status, DeflateError> {
294+
match crate::deflate::params(&mut self.0, level, Default::default()) {
295+
ReturnCode::Ok => Ok(Status::Ok),
296+
ReturnCode::StreamError => Err(DeflateError::StreamError),
297+
ReturnCode::BufError => Ok(Status::BufError),
298+
other => unreachable!("set_level does not return {other:?}"),
299+
}
300+
}
282301
}
283302

284303
impl Drop for Deflate {

0 commit comments

Comments
 (0)