diff options
author | Till Höppner | 2016-03-02 12:57:36 +0100 |
---|---|---|
committer | Till Höppner | 2016-03-02 12:57:36 +0100 |
commit | a4db0628a0377b39be02f0e83832b0c3527933e1 (patch) | |
tree | 375e33b2942b6374e352b554d7202664812ddf2f /tests/files/mod.rs | |
parent | 52d4c29f5bce85abadeb9fd394f55caf488b37f3 (diff) | |
download | ilc-a4db0628a0377b39be02f0e83832b0c3527933e1.tar.gz ilc-a4db0628a0377b39be02f0e83832b0c3527933e1.tar.xz ilc-a4db0628a0377b39be02f0e83832b0c3527933e1.zip |
Diffstat (limited to 'tests/files/mod.rs')
-rw-r--r-- | tests/files/mod.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/files/mod.rs b/tests/files/mod.rs new file mode 100644 index 0000000..5b25e90 --- /dev/null +++ b/tests/files/mod.rs @@ -0,0 +1,25 @@ +extern crate flate2; + +use std::fs::File; +use std::path::Path; +use std::io::{BufReader, Read, Write}; + +use self::flate2::FlateReadExt; + +#[allow(dead_code)] +pub fn read(path: &str) -> Vec<u8> { + let path = Path::new("tests").join("input").join(&format!("{}.gz", path)); + let size = path.metadata().expect("Couldn't determine filesize").len(); + let mut out = Vec::with_capacity(size as usize); + let mut input = BufReader::new(File::open(path).expect("Couldn't open file")) + .gz_decode() + .expect("Couldn't decode GZ stream"); + input.read_to_end(&mut out).expect("Couldn't read data"); + out +} + +#[allow(dead_code)] +pub fn write<P: AsRef<Path>>(p: P, b: &[u8]) { + let mut out = File::create(p).expect("Couldn't create file"); + out.write_all(b).expect("Couldn't write data"); +} |