From 81ae7e09f2d51bf3531378ecfb7f7071edd76284 Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Sun, 29 May 2016 12:13:49 +0200 Subject: [PATCH] Compress is working, I guess. Need to fix decompress to validate. --- src/main.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4cf2a8a..c407f6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,22 @@ +use std::env; +use std::fs; +use std::io::BufReader; +use std::io::prelude::*; use std::i32; fn main() { - let buf = "Hello world!"; + let output_filename = env::args().nth(1).unwrap(); + let mut output_file = fs::File::create(output_filename).unwrap(); + + let input_filename = env::args().nth(2).unwrap(); + let input_file = fs::File::open(input_filename).unwrap(); + let input_buf = BufReader::new(input_file); let mut i : i32 = 0; - for b in buf.chars() { - println!("{:?}", b); + for b in input_buf.bytes() { + let b = b.unwrap(); for n in 0..i32::MAX { if b == get_byte(n) { @@ -16,11 +25,11 @@ fn main() { } } - println!("{}", i); + output_file.write(&[i as u8]).unwrap(); } } -fn get_byte(id: i32) -> char { +fn get_byte(id: i32) -> u8 { let pid : f64 = 4.0 * series(1, id) - 2.0 * series(4, id) - series(5, id) - series(6, id); let mut y : f64 = (pid - (pid as i32) as f64 + 1.0).abs(); @@ -33,7 +42,7 @@ fn get_byte(id: i32) -> char { let second : u8 = y as u8; - ((first << 4) | second) as char + (first << 4) | second } fn series(m: i32, id: i32) -> f64 {