Skip to main content

rewrite_erf

Function rewrite_erf 

Source
pub fn rewrite_erf<'a, R, W>(
    source: &ErfIndex<R>,
    substitutions: impl IntoIterator<Item = (usize, &'a [u8])>,
    writer: &mut W,
) -> Result<(), ErfRewriteError>
where R: Read + Seek, W: Write,
Expand description

Writes source to writer, replacing the named entries’ bytes.

substitutions pairs a table position, as given by ErfIndex::entries or ErfIndex::position, with the bytes to store there. Every other entry is copied verbatim, as are the header, the localized string block and both tables.

§Errors

ErfRewriteError::NoSuchEntry and ErfRewriteError::DuplicateSubstitution for a bad substitution set, both checked before anything is written.

ErfRewriteError::UnreadableEntry when an entry that is not being replaced cannot be read. Supplying its bytes as a substitution is the way past this, which is how a damaged archive gets repaired rather than refused. ErfRewriteError::TruncatedEntry when such an entry reads and runs out before its declared size, and ErfRewriteError::OverlappingPayload when two entries claim the same bytes.

ErfRewriteError::RegionOutsidePrefix when the source’s string block or key table sits outside the span copied verbatim, since copying it would truncate them, and ErfRewriteError::KeyNamesMissingResourceRow when a key points at a row the resource table does not have.

ErfRewriteError::ValueOverflow when a recomputed offset or size will not fit its on-disk width, and ErfRewriteError::Io from either side. The I/O arm can leave a partial archive.