Skip to content

Commit e45857c

Browse files
committed
add inflate_bytes_zlib to exra::flate
1 parent 6c12ca3 commit e45857c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/libextra/flate.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static LZ_NONE : c_int = 0x0; // Huffman-coding only.
4343
static LZ_FAST : c_int = 0x1; // LZ with only one probe
4444
static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal"
4545
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
4647

4748
pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
4849
do bytes.as_imm_buf |b, len| {
@@ -62,15 +63,15 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
6263
}
6364
}
6465

65-
pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] {
66+
fn inflate_bytes_(bytes: &[u8], flags: c_int) -> ~[u8] {
6667
do bytes.as_imm_buf |b, len| {
6768
unsafe {
6869
let mut outsz : size_t = 0;
6970
let res =
7071
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
7172
len as size_t,
7273
&mut outsz,
73-
0);
74+
flags);
7475
assert!(res as int != 0);
7576
let out = vec::raw::from_buf_raw(res as *u8,
7677
outsz as uint);
@@ -80,6 +81,14 @@ pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] {
8081
}
8182
}
8283

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+
8392
#[cfg(test)]
8493
mod tests {
8594
use super::*;

0 commit comments

Comments
 (0)