It works!!!
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -2,9 +2,15 @@
|
|||||||
name = "picomp"
|
name = "picomp"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
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)",
|
"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]]
|
[[package]]
|
||||||
name = "getopts"
|
name = "getopts"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ authors = ["logaritmisk <anders.e.olsson@gmail.com>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "0.2"
|
getopts = "0.2"
|
||||||
|
byteorder = "0.5"
|
||||||
|
|||||||
26
src/main.rs
26
src/main.rs
@@ -1,12 +1,15 @@
|
|||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
extern crate byteorder;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::i32;
|
use std::i32;
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
|
use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
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) {
|
fn extract(input: &String, output: &String) {
|
||||||
let mut output_file = fs::File::create(output).unwrap();
|
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 mut buf = vec![0; 4];
|
||||||
let input_buf = BufReader::new(input_file);
|
|
||||||
|
|
||||||
for b in input_buf.bytes() {
|
loop {
|
||||||
let b = b.unwrap();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user