Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 20, 2020 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/9c506790bbce761c59c8b7419fd293be to your computer and use it in GitHub Desktop.
Save rust-play/9c506790bbce761c59c8b7419fd293be to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn ready_next_slice_from_idat(&mut self) -> Result<(), ZlibError> {
debug_assert!(self.spare_slice.is_empty());
match self.idat_iter.next() {
Some(Ok(sli)) => Ok(self.spare_slice = sli),
otherwise => Err(ZlibError::UnexpectedEndOfStream),
}
}
fn ready_next_byte(&mut self) -> Result<(), ZlibError> {
debug_assert!(self.spare_bits_count + 8 < 32);
if self.spare_slice.is_empty() {
self.ready_next_slice_from_idat()?
}
debug_assert!(!self.spare_slice.is_empty());
self.spare_bits |= u32::from(self.spare_slice[0]) << self.spare_bits_count;
self.spare_bits_count += 8;
#[cfg(not(feature = "png_skip_adler_checks"))]
{
self.adler = update_adler32(self.adler, &self.spare_slice[0..1]);
}
Ok(self.spare_slice = &self.spare_slice[1..])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment