extern crate npacked;
extern crate docopt;
use docopt::Docopt;
use npacked::Package;
use std::fs;
use std::io::{Read, Write};
/// Docopt usage string
const USAGE: &'static str = r#"
Usage: unnpk [options] [--]
Options:
-p, --prefix PREFIX Prefix outputed files with PREFIX [default: ./]
"#;
fn main() {
// Get arguments
let args = Docopt::new(USAGE).and_then(|d| d.parse()).unwrap();
let npk = Package::open(args.get_str("")).unwrap();
loop {
// Get a new file
let mut file = match npk.next_file() {
Ok(v) => match v {
Some(f) => f,
None => break
},
Err(e) => panic!(e)
};
// Open output file
let mut outfile = fs::File::create(args.get_str("-p").to_owned() +
file.name()).unwrap();
// Write out TODO replace with tee
let mut buf = Vec::::new();
file.read_to_end(&mut buf).unwrap();
outfile.write_all(buf.as_ref()).unwrap();
}
}