De-pub crc32 and rename some of the functions

This commit is contained in:
Mathijs van de Nes 2014-09-11 12:01:07 +02:00
parent 02059ce351
commit 3abe0aa893
5 changed files with 7 additions and 30 deletions

View file

@ -12,11 +12,6 @@ name = "extract"
test = false
doc = false
[[bin]]
name = "cksummer"
test = false
doc = false
[[bin]]
name = "write_sample"
test = false

View file

@ -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);
}

View file

@ -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<R: Reader> Reader for Crc32Reader<R>
},
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)
}
}

View file

@ -13,7 +13,7 @@ pub use writer::ZipWriter;
mod util;
mod spec;
pub mod crc32;
mod crc32;
mod reader;
pub mod types;
mod writer;

View file

@ -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;
}
}