blob: 5b25e90d028f08db161f6ad08962d34a847b752c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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");
}
|