[][src]Function niffler::get_reader

pub fn get_reader<'a>(
    in_stream: Box<dyn Read + 'a>
) -> Result<(Box<dyn Read + 'a>, Format), Error>

Create a readable stream that can be read transparently even if the original stream is compress. Also returns the compression type of the original stream.

Example

use niffler::{Error, get_reader};

let probably_compress_stream = std::io::Cursor::new(vec![
        0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 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
        ]);

let (mut reader, compression) = niffler::get_reader(Box::new(probably_compress_stream))?;

let mut contents = String::new();
reader.read_to_string(&mut contents).expect("Error durring file reading");

assert_eq!(compression, niffler::compression::Format::Gzip);
assert_eq!(contents, "I'm compress in gzip\n");