Skip to content

Commit

Permalink
read a file, print its title maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Dahan committed May 16, 2016
1 parent 1dc4976 commit 46ea228
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/main.rs
@@ -1,3 +1,40 @@
use std::env;
use std::fs;
use std::io::Read;

fn main() {
println!("Hello, world!");
let filename = env::args().nth(1).unwrap();
let mut file = fs::File::open(&filename).unwrap();
let mut buffer = Vec::new();
let _ = file.read_to_end(&mut buffer).unwrap();

println!("Opened {}, which is {} bytes", filename, buffer.len());

struct Range {
offset: usize,
length: usize
};

struct Header {
name: &'static str,
range: Range
};

let name_header = Header {
name: "title",
range: Range {
offset: 308,
length: 16
}
};

let headers = vec![name_header];

for header in headers {
let start = header.range.offset;
let end = header.range.offset + header.range.length - 1;
let mut header_slice = &buffer[start..end];
println!("{}: {}", header.name, String::from_utf8_lossy(&mut header_slice));
}

}

0 comments on commit 46ea228

Please sign in to comment.