From 280e70b37965797a41944ee876438176d98ca51a Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Sat, 20 Feb 2016 01:33:54 +0100 Subject: Add passthrough option --- lib/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/src/lib.rs') diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 20078a2..ce1e2ec 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -4,7 +4,8 @@ extern crate phf; extern crate flate2; use std::borrow::{Borrow, Cow}; -use std::io::{self, Cursor, Error, ErrorKind, Read}; +use std::io::{self, BufReader, Cursor, Error, ErrorKind, Read}; +use std::fs::File; #[cfg(feature = "flate2")] use flate2::FlateReadExt; @@ -12,6 +13,7 @@ use flate2::FlateReadExt; pub enum Compression { None, Gzip, + Passthrough, } /// Runtime access to the included files @@ -50,6 +52,12 @@ impl Files { } #[cfg(not(feature = "flate2"))] Compression::Gzip => panic!("Feature 'flate2' not enabled"), + Compression::Passthrough => { + let mut r = BufReader::new(try!(File::open(path))); + let mut v = Vec::new(); + try!(r.read_to_end(&mut v)); + Ok(Cow::Owned(v)) + } } } None => Err(Error::new(ErrorKind::NotFound, "Key not found")), @@ -66,6 +74,9 @@ impl Files { Compression::Gzip => Ok(Box::new(try!(Cursor::new(b.1).gz_decode()))), #[cfg(not(feature = "flate2"))] Compression::Gzip => panic!("Feature 'flate2' not enabled"), + Compression::Passthrough => { + Ok(Box::new(BufReader::new(try!(File::open(path))))) + } } } None => Err(Error::new(ErrorKind::NotFound, "Key not found")), -- cgit v1.2.3