2 releases
| 0.1.1 | Jan 25, 2026 |
|---|---|
| 0.1.0 | Jan 25, 2026 |
#1130 in Algorithms
33KB
759 lines
binhex
This crate provides a rust implementation for reading BinHex 4 files.
Introduced in 1995, the BinHex 4 format gained popularity in the early 90s among Macintosh users, as it combined Finder info of a file with its data and resource forks and wrapped everything up in a format that could easily and safely be shared via E-Mail and users on message boards.
As BinHex files are just ASCII text files, they can be hard to identify. If
present, the hqx file extension is a good indicator, otherwise the whole file
has to be searched progressively for the header indicating the start of encoded data.
The crate should be used by creating an Archive struct from an existing io::Read,
like a fs::File or io::Cursor.
use std::{io,fs};
use std::io::Read;
use macintosh_utils::fourcc;
// Open BinHex file
let mut archive = binhex::Archive::open("sample-file.hqx").unwrap();
// Read whole file and verify checksums
assert!(archive.verify().is_ok());
// Make sure we got the correct file
assert_eq!(archive.name(), "binhex.test.sit");
assert_eq!(archive.file_code(), fourcc!("SITD"));
// Read the data fork
let mut buffer = vec![0u8; archive.data_len()];
let mut data_fork_reader = archive.data_fork().unwrap();
data_fork_reader.read_exact(&mut buffer).unwrap();
// Read the resource fork
let mut buffer = vec![0u8; archive.resource_len() as usize];
let mut rsrc_fork_reader = archive.data_fork().unwrap();
rsrc_fork_reader.read_exact(&mut buffer).unwrap();
Dependencies
~6MB
~170K SLoC