# Macbinary-rs
> This crate aims to provide transparent access to macbinary files following the documentation at <https://github.com/mietek/theunarchiver/wiki/MacBinarySpecs>
## Usage
The intended usage is as follows
### Identifying MacBinary files
```rust
use macbinary::{MacBinary, Error, Version};
match macbinary::probe_file("./sample-file.sit") {
Ok(Version::None) => {}
Ok(Version::MacBinaryI) => {}
Ok(Version::MacBinaryII) => {}
Ok(Version::MacBinaryIII) => {}
Err(e) => eprintln!("Could not determine format of file: {:?}", e),
}
```
### Opening a file
```rust
use macbinary::Fork;
match macbinary::open_file("./sample-file.sit") {
Ok(mut file) => {
println!("File: {}", file.name());
println!("Type: {}/{}", file.creator_code(), file.type_code());
let mut reader = file.open_fork(Fork::Data).unwrap();
// .. read data from reader
},
Err(e) => eprintln!("Could not open file {:?}", e)
}
```
If file is not a macbinary, it will return sensible defaults for all fields, provide a transparent reader for the data fork and an empty reader for the resource fork.
## Limitations
At the moment the crate does not actually try to locate the resource fork if the opened file is not MacBinary encoded.
Checksum verification is not implemented.