extract_blob

Function extract_blob 

Source
pub fn extract_blob(bytes: &[u8], name_hint: &str) -> Result<PathBuf>
Expand description

Re-export of the blob extract / install helpers so the ktstr and cargo-ktstr binaries (separate crates linking this lib) can extract their include_bytes!-embedded blobs and export the paths at startup. The bytes live in each binary; the mechanism lives in the lib (the vmm::blobs module). Re-exported here because vmm is pub(crate), mirroring the wprof re-export above. Extract bytes to $TMPDIR/ktstr-blob-{name_hint}-{sha256:16} and return the path.

Content-addressed naming makes extraction idempotent across invocations: identical bytes always resolve to the same path, so a fresh invocation that finds a sized-matching file at the target reuses it instead of rewriting. A different blob (different bytes → different hash) writes a new file alongside; sweeping stale files is delegated to the OS $TMPDIR lifecycle (tmpfiles.d cleanup, container teardown, CI workspace wipe).

The hash is truncated to 16 hex chars (64 bits) — collision- resistant for the handful of blobs ktstr ships; the birthday bound against a 64-bit hash keeps the collision probability far below any rate that matters here.

Concurrency: two processes racing on the same blob both write a sibling staging tempfile and rename(2) it onto the target. rename is atomic on a single filesystem, and last-writer-wins is safe because both writers produce bit-identical content.