diff --git a/zlib-rs/src/deflate.rs b/zlib-rs/src/deflate.rs index df0e35d3..9070b6d9 100644 --- a/zlib-rs/src/deflate.rs +++ b/zlib-rs/src/deflate.rs @@ -691,7 +691,7 @@ impl<'a> State<'a> { "zng_tr_tally: bad literal" ); - self.sym_buf.filled().len() == self.sym_end + self.sym_buf.len() == self.sym_end } pub(crate) fn tally_dist(&mut self, mut dist: usize, len: usize) -> bool { @@ -712,7 +712,7 @@ impl<'a> State<'a> { *self.d_desc.dyn_tree[Self::d_code(dist) as usize].freq_mut() += 1; - self.sym_buf.filled().len() == self.sym_end + self.sym_buf.len() == self.sym_end } fn detect_data_type(dyn_tree: &[Value]) -> DataType { @@ -790,7 +790,7 @@ impl<'a> State<'a> { "pending_buf overflow" ); - if sx >= self.sym_buf.filled().len() { + if sx >= self.sym_buf.len() { break; } } diff --git a/zlib-rs/src/inflate.rs b/zlib-rs/src/inflate.rs index 5041b4df..64c043c5 100644 --- a/zlib-rs/src/inflate.rs +++ b/zlib-rs/src/inflate.rs @@ -857,7 +857,7 @@ impl<'a> State<'a> { } // this is not quite right. not sure when that matters - let out = self.writer.remaining() + self.writer.filled().len(); + let out = self.writer.remaining() + self.writer.len(); let left = self.writer.remaining(); let copy = out - left; @@ -1207,7 +1207,7 @@ fn inflate_fast_help(state: &mut State, _start: usize) -> ReturnCode { bit_reader.drop_bits(op as usize); // max distance in output - let written = writer.filled().len(); + let written = writer.len(); if dist as usize > written { // copy fropm the window @@ -1483,7 +1483,7 @@ pub unsafe fn inflate(stream: &mut InflateStream, flush: Flush) -> ReturnCode { stream.avail_in = state.bit_reader.bytes_remaining() as u32; stream.next_in = state.bit_reader.as_ptr() as *mut u8; - stream.avail_out = (state.writer.capacity() - state.writer.filled().len()) as u32; + stream.avail_out = (state.writer.capacity() - state.writer.len()) as u32; stream.next_out = state.writer.as_mut_ptr() as *mut u8; stream.adler = state.checksum as u64; diff --git a/zlib-rs/src/read_buf.rs b/zlib-rs/src/read_buf.rs index ad859dc9..69400dfb 100644 --- a/zlib-rs/src/read_buf.rs +++ b/zlib-rs/src/read_buf.rs @@ -75,6 +75,12 @@ impl<'a> ReadBuf<'a> { self.buf.len() } + /// Returns the length of the filled part of the buffer + #[inline] + pub fn len(&self) -> usize { + self.filled + } + /// Returns true if there are no bytes in this ReadBuf #[inline] pub fn is_empty(&self) -> bool { @@ -132,7 +138,7 @@ impl<'a> ReadBuf<'a> { /// Returns a mutable reference to the entire buffer, without ensuring that it has been fully /// initialized. /// - /// The elements between 0 and `self.filled().len()` are filled, and those between 0 and + /// The elements between 0 and `self.len()` are filled, and those between 0 and /// `self.initialized().len()` are initialized (and so can be converted to a `&mut [u8]`). /// /// The caller of this method must ensure that these invariants are upheld. For example, if the