Skip to main content

Crate binhex_rs

Crate binhex_rs 

Source
Expand description

§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 fourcc_rs::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();

Structs§

Archive
Reader for BinHex archives
ArchiveHeader
On-disk structure describing contents of the BinHex archive
ForkReader
Reader for data or resource fork embedded in an archive

Enums§

Checksum
Identifies the location where checksum verification failed
Error
General error used by the crate
VerificationError
Error used to signal invalid checksums

Functions§

probe