It works!... not. Cant cast i32 to u8...

This commit is contained in:
2016-05-29 13:00:08 +02:00
parent 81ae7e09f2
commit 24317fc750
3 changed files with 58 additions and 5 deletions

View File

@@ -1,16 +1,47 @@
extern crate getopts;
use std::env;
use std::fs;
use std::io::BufReader;
use std::io::prelude::*;
use std::i32;
use getopts::Options;
fn main() {
let output_filename = env::args().nth(1).unwrap();
let mut output_file = fs::File::create(output_filename).unwrap();
let args: Vec<String> = env::args().collect();
let input_filename = env::args().nth(2).unwrap();
let input_file = fs::File::open(input_filename).unwrap();
let mut opts = Options::new();
opts.optflag("c", "", "create file");
opts.optflag("x", "", "extract file");
opts.optopt("i", "", "input file", "NAME");
opts.optopt("o", "", "output file", "NAME");
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(f) => { panic!(f.to_string()) }
};
if matches.opt_present("c") {
let input = matches.opt_str("i").unwrap();
let output = matches.opt_str("o").unwrap();
create(&input, &output);
}
else if matches.opt_present("x") {
let input = matches.opt_str("i").unwrap();
let output = matches.opt_str("o").unwrap();
extract(&input, &output)
}
}
fn create(input: &String, output: &String) {
let mut output_file = fs::File::create(output).unwrap();
let input_file = fs::File::open(input).unwrap();
let input_buf = BufReader::new(input_file);
let mut i : i32 = 0;
@@ -25,7 +56,20 @@ fn main() {
}
}
output_file.write(&[i as u8]).unwrap();
output_file.write_all(&[i as u8]).unwrap();
}
}
fn extract(input: &String, output: &String) {
let mut output_file = fs::File::create(output).unwrap();
let input_file = fs::File::open(input).unwrap();
let input_buf = BufReader::new(input_file);
for b in input_buf.bytes() {
let b = b.unwrap();
output_file.write(&[get_byte(b as i32)]).unwrap();
}
}