Hi,
I'm still in the learning phase of Rust. With a pre-1.0 release of Rust I had already working code to read a binary Blender file and analyze the header and all remaining chunks. The old code can be found here. Anyway, back to the question. The new code compiles, but I'm stuck with how I can continue reading the chunks after having read the header information. Probably I'm doing something wrong. So here is the main idea of what I have done so far:
fn main() {
// deal with command line arguments
...
do_work(&input, output);
}
An interesting detail I learned was that I had to be within a function which returns io::Result<()> to be able to use the try! macro, so from within do_work(...) I call read_blend_file(...) with the following signature:
fn read_blend_file(inp: &str) -> io::Result<()> {
// open file
let file = try!(File::open(inp));
// read 12 bytes from the Blender file
let mut take = file.take(12u64);
let mut header = String::new();
try!(take.read_to_string(&mut header));
println!("header = \"{}\"", header);
// analyze header
...
Ok(())
}
I use file.take(...) to read the first 12 bytes and perform several tests before I continue.
So my question is: How do I continue reading the binary file with different chunk sizes?
The old code was like this:
// assumes 64-bit pointers (in file as well as on platform)
loop {
// read_file_dna
let io_result = file.read_exact(24); // 4 * int + 64-bit pointer
...
}
Thanks in advance for any help on this topic. Maybe there are some examples (code snippets) somewhere?
Jan