acr 0.4.3

All shared code across the whole Acridotheres project
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use dh::{Readable, Writable};
use inflate::inflate_bytes_zlib;
use std::io::{Error, ErrorKind, Result};

pub fn decompress<'a, W: Writable<'a>>(source: &mut dyn Readable, target: &mut W) -> Result<u64> {
    let len = source.size()?;
    let data = source.read_bytes(len)?;
    match inflate_bytes_zlib(&data) {
        Ok(data) => {
            target.write_bytes(&data)?;
            Ok(data.len() as u64)
        }
        Err(e) => Err(Error::new(
            ErrorKind::Other,
            "Deflate w/ zlib decompression error: ".to_string() + &e.to_string(),
        )),
    }
}