Skip to main content

reassemble

Function reassemble 

Source
pub fn reassemble(
    collection: &PartCollection,
) -> Result<ReassembledFile, MultiUuError>
Expand description

Reassemble a multi-part UU-encoded file from its parts.

Iterates over all PartEntry values with part_number >= 1 in ascending order (the PartCollection’s BTreeMap guarantees this). Each part’s body_bytes is independently decoded via uuencoding::decode and the decoded payloads are concatenated. filename and mode are taken from the first part only.

The TOC part (part_number = 0), if present, is silently ignored.

§Errors

  • MultiUuError::EmptyCollection — the collection contains no parts with part_number >= 1 (including the case of a TOC-only collection).
  • MultiUuError::DecodeErroruuencoding::decode returned an error for one of the parts. Reassembly stops at the first failing part.

§Partial results

When parts are missing the function still returns Ok rather than an error. The result has is_truncated = true and missing_parts listing the absent part numbers. data contains the concatenation of the parts that were present, which is useful for diagnostic inspection.

§Never panics

This function never panics. The expect on the internal get() call is unreachable by construction: present_parts() only yields numbers that are keys in the underlying map.

§Security

The decoded data may be a compressed archive. Any subsequent decompression is the caller’s responsibility and must be independently guarded against decompression-bomb attacks. This crate does not decompress.

§Example

use uuencoding_multi::{PartCollection, PartEntry, reassemble};

// In practice `body_bytes` comes from message parts fetched from NNTP
// or a mailbox; `no_run` is used here because constructing valid UU
// bodies inline is verbose.
let mut coll = PartCollection::with_total(2);
coll.add(PartEntry { part_number: 1, body_bytes: todo!(), subject: None }).unwrap();
coll.add(PartEntry { part_number: 2, body_bytes: todo!(), subject: None }).unwrap();

let file = reassemble(&coll).unwrap();
assert!(!file.is_truncated);
// Apply size limits before decompressing file.data.
println!("{}: {} bytes", file.filename, file.data.len());