It works!!!

This commit is contained in:
2016-05-29 21:28:08 +02:00
parent 24317fc750
commit 4815cd6817
3 changed files with 27 additions and 6 deletions

6
Cargo.lock generated
View File

@@ -2,9 +2,15 @@
name = "picomp"
version = "0.1.0"
dependencies = [
"byteorder 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "getopts"
version = "0.2.14"

View File

@@ -5,3 +5,4 @@ authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
[dependencies]
getopts = "0.2"
byteorder = "0.5"

View File

@@ -1,12 +1,15 @@
extern crate getopts;
extern crate byteorder;
use std::env;
use std::fs;
use std::io::BufReader;
use std::io::prelude::*;
use std::i32;
use std::io::Cursor;
use getopts::Options;
use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
fn main() {
@@ -56,20 +59,31 @@ fn create(input: &String, output: &String) {
}
}
output_file.write_all(&[i as u8]).unwrap();
let mut out : Vec<u8> = vec![];
out.write_i32::<LittleEndian>(i).unwrap();
output_file.write_all(&out).unwrap();
}
}
fn extract(input: &String, output: &String) {
let mut output_file = fs::File::create(output).unwrap();
let mut input_file = fs::File::open(input).unwrap();
let input_file = fs::File::open(input).unwrap();
let input_buf = BufReader::new(input_file);
let mut buf = vec![0; 4];
for b in input_buf.bytes() {
let b = b.unwrap();
loop {
let size = input_file.read(&mut buf).unwrap();
output_file.write(&[get_byte(b as i32)]).unwrap();
if size <= 0 {
break;
}
let mut c = Cursor::new(&buf);
let index = c.read_i32::<LittleEndian>().unwrap();
output_file.write_all(&[get_byte(index)]).unwrap();
}
}