uuencoding
UUencoding and UUdecoding for Rust — encode, decode, and scan for UU blocks.
UUencoding (Unix-to-Unix encoding) is a binary-to-text encoding from the UUCP/Usenet era
(1980s). It appears in email as Content-Transfer-Encoding: x-uuencode and as inline
begin/end blocks embedded in text/plain message bodies.
Features
encode(data, filename, mode)— produce a well-formedbegin/endUU blockdecode(input)— decode a full UU block includingbegin/endframingdecode_limited(input, max_bytes)— preview-efficient decode with a byte capscan(input)— find and decode all UU blocks by byte offset in arbitrary text- Handles real-world noise: CRLF line endings, trailing-space stripping by mail relays,
space/backtick ambiguity for zero, missing
endlines,begin-base64detection DecodedBlock::was_limit_hitdistinguishes preview truncation from encoding errors- No panics on any input
- No unsafe code
- MSRV: 1.75
Usage
use ;
// Encode
let encoded = encode;
// Decode the full block
let block = decode.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
// Decode only the first 5 bytes (preview)
let preview = decode_limited.unwrap;
assert_eq!;
assert!;
assert!; // stopped by limit, not an encoding error
// Scan arbitrary text for embedded blocks
let text = b"Some prose.\nbegin 644 hello.txt\n%2&5L;&\\ \n \nend\nMore prose.\n";
for result in scan
Error types
Partial results and truncation
Both decode and decode_limited return Ok even when the block is malformed:
| Condition | is_truncated |
was_limit_hit |
|---|---|---|
| Complete, well-formed block | false |
false |
Stopped by max_bytes limit |
true |
true |
Missing end line or bad data byte |
true |
false |
Security
Decoded output can be substantially larger than encoded input (ratio up to 3:4). If the decoded bytes are a compressed archive, any decompression is the caller's responsibility and must be independently guarded against decompression bombs. This crate does not decompress.
License
MIT OR Apache-2.0