Skip to main content

replace_metadata

Function replace_metadata 

Source
pub fn replace_metadata(
    image: &[u8],
    metadata: &[u8],
) -> Result<Vec<u8>, FileError>
Expand description

Replace the metadata section (the Dataset Card blob) of a finished file image, returning the new image. The section is the first one after the header, so every later section’s offset shifts by the length delta.

Unlike attach_build_info, the metadata payload is inside the content hash — it is part of what the file says about itself — so the hash is recomputed here. The result is byte-identical to what the writer would have produced had it been handed this payload in the first place (write_dataset_with_metadata): the section sits at HEADER_LEN, every later offset is derived from its length, and the hash folds the same parts in the same order.

Why splice rather than rebuild: the only caller that needs this is a build that has already assembled the file and then learned something about it by running its own starter queries against it. Re-deriving the whole image to correct a metadata blob would mean re-parsing the input; a splice costs one memcpy and one rehash of an image that is already resident.

Passing an empty payload removes the section.