diff --git a/Cargo.toml b/Cargo.toml index b9c5f7f8..b6a82996 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,6 @@ name = "extract" test = false doc = false -[[bin]] -name = "cksummer" -test = false -doc = false - [[bin]] name = "write_sample" test = false diff --git a/src/bin/cksummer.rs b/src/bin/cksummer.rs deleted file mode 100644 index dcc02ae4..00000000 --- a/src/bin/cksummer.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate zip; - -fn main() -{ - let mut stdin = std::io::stdin(); - let mut crc = 0u32; - let mut buf = [0u8, ..4096]; - - loop - { - match stdin.read(&mut buf) - { - Err(_) => break, - Ok(n) => { crc = zip::crc32::crc32(crc, buf.slice_to(n)); }, - } - } - - println!("{:x}", crc); -} diff --git a/src/crc32.rs b/src/crc32.rs index b2578c2c..673a9109 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -48,10 +48,10 @@ static CRC32_TABLE : [u32, ..256] = [ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d ]; -/// Update the checksum original based upon the contents of buf. -pub fn crc32(original: u32, buf: &[u8]) -> u32 +/// Update the checksum prev based upon the contents of buf. +pub fn update(prev: u32, buf: &[u8]) -> u32 { - let mut crc = original ^ !0u32; + let mut crc = prev ^ !0u32; for byte in buf.iter() { @@ -103,7 +103,7 @@ impl Reader for Crc32Reader }, Err(e) => return Err(e), }; - self.crc = crc32(self.crc, buf.slice_to(count)); + self.crc = update(self.crc, buf.slice_to(count)); Ok(count) } } diff --git a/src/lib.rs b/src/lib.rs index 5632ea47..7f3a7bf8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ pub use writer::ZipWriter; mod util; mod spec; -pub mod crc32; +mod crc32; mod reader; pub mod types; mod writer; diff --git a/src/writer.rs b/src/writer.rs index 580f1809..dba838b3 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -1,6 +1,7 @@ use types; use types::ZipFile; use spec; +use crc32; use std::default::Default; use std::io; use std::io::{IoResult, IoError}; @@ -77,7 +78,7 @@ impl ZipWriterStats { fn update(&mut self, buf: &[u8]) { - self.crc32 = ::crc32::crc32(self.crc32, buf); + self.crc32 = crc32::update(self.crc32, buf); self.bytes_written += buf.len() as u64; } }