pub fn parse_toc(body_bytes: &[u8]) -> Option<ParsedToc>Expand description
Best-effort parse of a UUencode multi-part TOC body.
The input is treated as a sequence of lines. Each line is independently attempted against three recognised TOC formats (in priority order):
- Part-range prefix:
01-08 filename.tar.gz 1234 KB - Parenthesised size:
filename.tar.gz (1234567 bytes) - Inline size/parts:
filename.tar.gz 1234567 bytes parts 1-8
Lines that match none of these formats (comments starting with #, blank
lines, plain prose) are silently ignored. This makes the parser tolerant
of the varied free-form headers that real TOC posts contain.
§Return value
Returns None if no lines at all parse as TOC entries.
Returns Some(ParsedToc) with partial entries if at least one line
parses; unparseable lines are omitted without error.
§Format notes
- Size units
bytes/b,KB, andMBare recognised case-insensitively. KB and MB are converted to bytes using powers of 1 024. - Part ranges use an inclusive dash notation (
N-M). Inverted ranges whereN > Mare rejected and produceNonefor that field. - Non-UTF-8 bytes in
body_bytesare replaced via lossy conversion and preserved verbatim inParsedToc::raw_text.
§Never panics
This function never panics on any input, including empty slices and byte sequences that are not valid UTF-8.
§Examples
use uuencoding_multi::parse_toc;
let body = b"archive.tar.gz 1234567 bytes parts 1-8\n";
let toc = parse_toc(body).expect("should parse");
assert_eq!(toc.entries.len(), 1);
assert_eq!(toc.entries[0].filename, "archive.tar.gz");
assert_eq!(toc.entries[0].size_bytes, Some(1_234_567));
assert_eq!(toc.entries[0].parts, Some(1..=8));use uuencoding_multi::parse_toc;
// Body with no recognisable TOC lines → None.
assert!(parse_toc(b"just plain text\n").is_none());use uuencoding_multi::parse_toc;
// Empty input → None.
assert!(parse_toc(b"").is_none());