[][src]Function niffler::get_writer

pub fn get_writer<'a>(
    out_stream: Box<dyn Write + 'a>,
    format: Format,
    level: Level
) -> Result<Box<dyn Write + 'a>, Error>

Create a new writable stream with the given compression format and level.

Example

This example is not tested
use std::io::Read;
use niffler::{Error, get_writer, compression};

let wfile = Box::new(std::fs::File::create("output.gz").expect("Can't open output file"));
let mut writer = niffler::get_writer(wfile, compression::Format::Gzip, compression::Level::One)?;
writer.write_all("I'm compress in gzip\n".as_bytes()).expect("Error during write of data");
drop(writer);

let mut rfile = std::fs::File::open("output.gz").expect("Can't open file");
let mut contents = Vec::new();
rfile.read_to_end(&mut contents);

assert_eq!(contents, vec![
        0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff, 0xf3, 0x54, 0xcf, 0x55,
        0x48, 0xce, 0xcf, 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x56, 0xc8, 0xcc, 0x53, 0x48, 0xaf,
        0xca, 0x2c, 0xe0, 0x02, 0x00, 0x45, 0x7c, 0xf4, 0x10, 0x15, 0x00, 0x00, 0x00
        ]);