aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Cargo.toml2
-rw-r--r--lib/src/lib.rs9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/Cargo.toml b/lib/Cargo.toml
index aa82ad8..732ddd6 100644
--- a/lib/Cargo.toml
+++ b/lib/Cargo.toml
@@ -14,4 +14,4 @@ default = ["flate2"]
[dependencies]
phf = "0.7.12"
-flate2 = { version = "*", optional = true }
+flate2 = { version = "0.2.13", optional = true }
diff --git a/lib/src/lib.rs b/lib/src/lib.rs
index 666c727..20078a2 100644
--- a/lib/src/lib.rs
+++ b/lib/src/lib.rs
@@ -1,9 +1,12 @@
extern crate phf;
+
+#[cfg(feature = "flate2")]
extern crate flate2;
use std::borrow::{Borrow, Cow};
use std::io::{self, Cursor, Error, ErrorKind, Read};
+#[cfg(feature = "flate2")]
use flate2::FlateReadExt;
pub enum Compression {
@@ -38,12 +41,15 @@ impl Files {
Some(b) => {
match b.0 {
Compression::None => Ok(Cow::Borrowed(b.1)),
+ #[cfg(feature = "flate2")]
Compression::Gzip => {
let mut r = try!(Cursor::new(b.1).gz_decode());
let mut v = Vec::new();
try!(r.read_to_end(&mut v));
Ok(Cow::Owned(v))
}
+ #[cfg(not(feature = "flate2"))]
+ Compression::Gzip => panic!("Feature 'flate2' not enabled"),
}
}
None => Err(Error::new(ErrorKind::NotFound, "Key not found")),
@@ -56,7 +62,10 @@ impl Files {
Some(b) => {
match b.0 {
Compression::None => Ok(Box::new(Cursor::new(b.1))),
+ #[cfg(feature = "flate2")]
Compression::Gzip => Ok(Box::new(try!(Cursor::new(b.1).gz_decode()))),
+ #[cfg(not(feature = "flate2"))]
+ Compression::Gzip => panic!("Feature 'flate2' not enabled"),
}
}
None => Err(Error::new(ErrorKind::NotFound, "Key not found")),