From: darkf Date: Mon, 5 Aug 2013 05:28:53 +0000 (-0700) Subject: add inflate_bytes_zlib to exra::flate X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=9b221f56f1d9f923fad48b7e30f886acaeb3f741;p=rust.git add inflate_bytes_zlib to exra::flate --- diff --git a/src/libextra/flate.rs b/src/libextra/flate.rs index 8024b9aa159..5d5180c152b 100644 --- a/src/libextra/flate.rs +++ b/src/libextra/flate.rs @@ -43,6 +43,7 @@ pub fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void, static LZ_FAST : c_int = 0x1; // LZ with only one probe static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal" static LZ_BEST : c_int = 0xfff; // LZ with 4095 probes, "best" +static TINFL_FLAG_PARSE_ZLIB_HEADER : c_int = 0x1; // parse zlib header and adler32 checksum pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] { do bytes.as_imm_buf |b, len| { @@ -62,7 +63,7 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] { } } -pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] { +fn inflate_bytes_(bytes: &[u8], flags: c_int) -> ~[u8] { do bytes.as_imm_buf |b, len| { unsafe { let mut outsz : size_t = 0; @@ -70,7 +71,7 @@ pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] { rustrt::tinfl_decompress_mem_to_heap(b as *c_void, len as size_t, &mut outsz, - 0); + flags); assert!(res as int != 0); let out = vec::raw::from_buf_raw(res as *u8, outsz as uint); @@ -80,6 +81,14 @@ pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] { } } +pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] { + inflate_bytes_(bytes, 0) +} + +pub fn inflate_bytes_zlib(bytes: &[u8]) -> ~[u8] { + inflate_bytes_(bytes, TINFL_FLAG_PARSE_ZLIB_HEADER) +} + #[cfg(test)] mod tests { use super::*;