binhex-rs

Crates.iobinhex-rs
lib.rsbinhex-rs
version0.1.1
created_at2026-01-25 10:24:27.53559+00
updated_at2026-01-25 16:58:04.859933+00
descriptionCrate to read BinHex 4 encoded files
homepage
repositoryhttps://codeberg.org/cyco/binhex-rs
max_upload_size
id2068504
size63,287
(cyco)

documentation

README

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();
Commit count: 5

cargo fmt