[−][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
use std::io::Read; use niffler::{Error, get_writer, compression}; let mut buffer = vec![]; { let mut writer = niffler::get_writer(Box::new(&mut buffer), compression::Format::Gzip, compression::Level::One)?; writer.write_all("I'm compress in gzip\n".as_bytes())? } let mut contents = Vec::new(); buffer.as_slice().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 ]);