]> git.lizzy.rs Git - rust.git/commitdiff
add inflate_bytes_zlib to exra::flate
authordarkf <lw9k123@gmail.com>
Mon, 5 Aug 2013 05:28:53 +0000 (22:28 -0700)
committerCorey Richardson <corey@octayn.net>
Thu, 8 Aug 2013 02:41:13 +0000 (22:41 -0400)
src/libextra/flate.rs

index 8024b9aa1596cddbbff48c25cf0a11ae78f06334..5d5180c152b17bc3ee13ba79fed3df76de5b5733 100644 (file)
@@ -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::*;