diff --git a/Cargo.toml b/Cargo.toml index d41209c5..16ec116d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ version = "1.1.7" edition = "2018" license = "MIT OR Apache-2.0" readme = "README.md" -rust-version = "1.67.0" +rust-version = "1.89.0" keywords = ["gzip", "deflate", "zlib", "zlib-ng", "encoding"] categories = ["compression", "api-bindings"] repository = "https://github.com/rust-lang/flate2-rs" @@ -27,8 +27,8 @@ cloudflare-zlib-sys = { version = "0.3.6", optional = true } ## This implementation uses only safe Rust code and doesn't require a C compiler. ## It provides good performance for most use cases while being completely portable. miniz_oxide = { version = "0.8.5", optional = true, default-features = false, features = ["with-alloc", "simd"] } -crc32fast = "1.2.0" document-features = { version = "0.2", optional = true } +crc-fast = "1.10.0" [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] miniz_oxide = { version = "0.8.5", default-features = false, features = ["with-alloc", "simd"] } diff --git a/src/crc.rs b/src/crc.rs index 991cc957..ab63fd94 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -3,15 +3,14 @@ use std::io; use std::io::prelude::*; -use crc32fast::Hasher; +use crc_fast::{CrcAlgorithm, Digest}; /// The CRC calculated by a [`CrcReader`]. /// /// [`CrcReader`]: struct.CrcReader.html -#[derive(Debug, Default)] +#[derive(Debug, Clone)] pub struct Crc { - amt: u32, - hasher: Hasher, + digest: Digest, } /// A wrapper around a [`Read`] that calculates the CRC. @@ -23,39 +22,44 @@ pub struct CrcReader { crc: Crc, } +impl Default for Crc { + fn default() -> Self { + Self::new() + } +} + impl Crc { /// Create a new CRC. pub fn new() -> Self { - Self::default() + Crc { + digest: Digest::new(CrcAlgorithm::Crc32IsoHdlc), + } } /// Returns the current crc32 checksum. pub fn sum(&self) -> u32 { - self.hasher.clone().finalize() + self.digest.finalize() as u32 } /// The number of bytes that have been used to calculate the CRC. /// This value is only accurate if the amount is lower than 232. pub fn amount(&self) -> u32 { - self.amt + self.digest.get_amount() as u32 } /// Update the CRC with the bytes in `data`. pub fn update(&mut self, data: &[u8]) { - self.amt = self.amt.wrapping_add(data.len() as u32); - self.hasher.update(data); + self.digest.update(data); } /// Reset the CRC. pub fn reset(&mut self) { - self.amt = 0; - self.hasher.reset(); + self.digest.reset(); } /// Combine the CRC with the CRC for the subsequent block of bytes. pub fn combine(&mut self, additional_crc: &Crc) { - self.amt = self.amt.wrapping_add(additional_crc.amt); - self.hasher.combine(&additional_crc.hasher); + self.digest.combine(&additional_crc.digest); } }