Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to miniz_oxide 0.4 #235

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ include = [
]

[dependencies]
miniz_oxide = "0.3.5"
deflate = { version = "0.8.2", optional = true }
bitflags = "1.0"
crc32fast = "1.2.0"
[dependencies.miniz_oxide]
version = "0.4.1"
features = ["no_extern_crate_alloc"]

[dev-dependencies]
criterion = "0.3.1"
Expand Down
21 changes: 14 additions & 7 deletions src/decoder/zlib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{DecodingError, CHUNCK_BUFFER_SIZE};
use std::io;

use miniz_oxide::inflate::core::{decompress, inflate_flags, DecompressorOxide};
use miniz_oxide::inflate::TINFLStatus;
Expand Down Expand Up @@ -67,14 +66,18 @@ impl ZlibStream {
self.prepare_vec_for_appending();

let (status, mut in_consumed, out_consumed) = {
let mut cursor = io::Cursor::new(self.out_buffer.as_mut_slice());
cursor.set_position(self.out_pos as u64);
let in_data = if self.in_buffer.is_empty() {
data
} else {
&self.in_buffer[self.in_pos..]
};
decompress(&mut self.state, in_data, &mut cursor, BASE_FLAGS)
decompress(
&mut self.state,
in_data,
&mut self.out_buffer.as_mut_slice(),
self.out_pos,
BASE_FLAGS,
)
};

if !self.in_buffer.is_empty() {
Expand Down Expand Up @@ -130,9 +133,13 @@ impl ZlibStream {
// TODO: we may be able to avoid the indirection through the buffer here.
// First append all buffered data and then create a cursor on the image_data
// instead.
let mut cursor = io::Cursor::new(self.out_buffer.as_mut_slice());
cursor.set_position(self.out_pos as u64);
decompress(&mut self.state, &tail[start..], &mut cursor, BASE_FLAGS)
decompress(
&mut self.state,
&tail[start..],
&mut self.out_buffer.as_mut_slice(),
self.out_pos,
BASE_FLAGS,
)
};

start += in_consumed;
Expand Down