@@ -43,6 +43,7 @@ static LZ_NONE : c_int = 0x0; // Huffman-coding only.
43
43
static LZ_FAST : c_int = 0x1 ; // LZ with only one probe
44
44
static LZ_NORM : c_int = 0x80 ; // LZ with 128 probes, "normal"
45
45
static LZ_BEST : c_int = 0xfff ; // LZ with 4095 probes, "best"
46
+ static TINFL_FLAG_PARSE_ZLIB_HEADER : c_int = 0x1 ; // parse zlib header and adler32 checksum
46
47
47
48
pub fn deflate_bytes ( bytes : & [ u8 ] ) -> ~[ u8 ] {
48
49
do bytes. as_imm_buf |b, len| {
@@ -62,15 +63,15 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
62
63
}
63
64
}
64
65
65
- pub fn inflate_bytes ( bytes : & [ u8 ] ) -> ~[ u8 ] {
66
+ fn inflate_bytes_ ( bytes : & [ u8 ] , flags : c_int ) -> ~[ u8 ] {
66
67
do bytes. as_imm_buf |b, len| {
67
68
unsafe {
68
69
let mut outsz : size_t = 0 ;
69
70
let res =
70
71
rustrt:: tinfl_decompress_mem_to_heap ( b as * c_void ,
71
72
len as size_t ,
72
73
& mut outsz,
73
- 0 ) ;
74
+ flags ) ;
74
75
assert ! ( res as int != 0 ) ;
75
76
let out = vec:: raw:: from_buf_raw ( res as * u8 ,
76
77
outsz as uint ) ;
@@ -80,6 +81,14 @@ pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] {
80
81
}
81
82
}
82
83
84
+ pub fn inflate_bytes ( bytes : & [ u8 ] ) -> ~[ u8 ] {
85
+ inflate_bytes_ ( bytes, 0 )
86
+ }
87
+
88
+ pub fn inflate_bytes_zlib ( bytes : & [ u8 ] ) -> ~[ u8 ] {
89
+ inflate_bytes_ ( bytes, TINFL_FLAG_PARSE_ZLIB_HEADER )
90
+ }
91
+
83
92
#[ cfg( test) ]
84
93
mod tests {
85
94
use super :: * ;
0 commit comments