diff options
author | Till Höppner | 2016-02-20 01:33:54 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-20 01:33:54 +0100 |
commit | 280e70b37965797a41944ee876438176d98ca51a (patch) | |
tree | bd69cbf46a8587e42829eaa27dae10e71a0c43ea /lib/src/lib.rs | |
parent | 6996b19389701c1c8809827ec4349172302f12b1 (diff) | |
download | includedir-280e70b37965797a41944ee876438176d98ca51a.tar.gz includedir-280e70b37965797a41944ee876438176d98ca51a.tar.xz includedir-280e70b37965797a41944ee876438176d98ca51a.zip |
Add passthrough option
Diffstat (limited to 'lib/src/lib.rs')
-rw-r--r-- | lib/src/lib.rs | 13 |
1 files changed, 12 insertions, 1 deletions
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")), |