Function niffler::basic::sniff[][src]

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

Finds out what is the compression format for a stream based on magic numbers (the first few bytes of the stream).

Return the stream and the compression format detected.

Example


let data = 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::sniff(Box::new(&data[..]))?;

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

assert_eq!(compression, niffler::compression::Format::Gzip);
assert_eq!(contents, data);