MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / extract_first_tar_entry

Function extract_first_tar_entry

crates/openshell-driver-docker/src/lib.rs:3303–3317  ·  view source on GitHub ↗

Extract the payload of the first regular-file entry in a tar archive. Docker's `/containers/ /archive` endpoint returns a single-file tar when `path` points to a file, so we only need the first entry.

(tar_bytes: &[u8])

Source from the content-addressed store, hash-verified

3301/// Docker's `/containers/<id>/archive` endpoint returns a single-file tar
3302/// when `path` points to a file, so we only need the first entry.
3303fn extract_first_tar_entry(tar_bytes: &[u8]) -> Result<Vec<u8>, String> {
3304 let mut archive = tar::Archive::new(std::io::Cursor::new(tar_bytes));
3305 let mut entries = archive
3306 .entries()
3307 .map_err(|err| format!("open tar archive: {err}"))?;
3308 let mut entry = entries
3309 .next()
3310 .ok_or_else(|| "tar archive was empty".to_string())?
3311 .map_err(|err| format!("read tar entry: {err}"))?;
3312 let mut bytes = Vec::new();
3313 entry
3314 .read_to_end(&mut bytes)
3315 .map_err(|err| format!("read tar entry payload: {err}"))?;
3316 Ok(bytes)
3317}
3318
3319fn write_cache_binary_atomic(final_path: &Path, bytes: &[u8]) -> CoreResult<()> {
3320 let dir = final_path.parent().ok_or_else(|| {

Calls 1

nextMethod · 0.45