Skip to main content

Module binhex

Module binhex 

Source
Expand description

BinHex 4.0 (.hqx) encode + decode.

BinHex 4.0 is the classic Macintosh 7-bit-safe encoding that preserves a file’s data fork, resource fork, and Finder info (type/creator/flags) in a single ASCII text file. Layout of the decoded byte stream:

nameLen(1) name(nameLen) version(1=0) type(4) creator(4) flags(2)
dataLen(4) rsrcLen(4) headerCRC(2)
<data fork bytes> dataCRC(2)
<resource fork bytes> rsrcCRC(2)

That whole byte stream is RLE90-compressed (0x90 run marker) and then 6-bit encoded into the BinHex alphabet, wrapped between : markers under the (This file must be converted with BinHex 4.0) banner.

CRCs are CRC-16-CCITT (poly 0x1021, init 0) in augmented form: the running CRC is finalized by feeding two trailing zero bytes. This differs from the MacBinary CRC in resource_fork.rs (which stores the CRC directly). Reference: hfsutils src/common/crc.c crc_binh + src/binhex/binhex.c, and XADMaster XADBinHexParser.m.

Structs§

BinHexFile
A file decoded from / to be encoded into BinHex 4.0.

Functions§

build_binhex
Encode a BinHexFile into a complete .hqx text document.
parse_binhex
Decode a .hqx document into a BinHexFile, verifying all CRCs.
rle90_decode
RLE90 decompress (inverse of rle90_encode). Shared with the StuffIt reader, which uses the same 0x90 run encoding for compression method 1.
rle90_encode
RLE90 compress: a run of b repeated n (3..=255) times becomes b 0x90 n; a literal 0x90 becomes 0x90 0x00. Shared with the StuffIt writer (compression method 1).