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§
- BinHex
File - A file decoded from / to be encoded into BinHex 4.0.
Functions§
- build_
binhex - Encode a
BinHexFileinto a complete.hqxtext document. - parse_
binhex - Decode a
.hqxdocument into aBinHexFile, 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
brepeatedn(3..=255) times becomesb 0x90 n; a literal0x90becomes0x90 0x00. Shared with the StuffIt writer (compression method 1).