Skip to content

archive

The archive module provides in-memory creation and extraction of zip and tar archives. Archives are represented as Array<int> byte arrays. Individual entries are objects with name and data string fields.

use std::core::archive

Archive entries are HashMaps with two fields:

FieldTypeDescription
namestringFile path within the archive
datastringFile contents as text

archive::zip_create(entries: Array<{name, data}>) -> Array<int>

Section titled “archive::zip_create(entries: Array<{name, data}>) -> Array<int>”

Create a zip archive in memory from an array of entries. Files are compressed using deflate.

let zip_bytes = archive::zip_create([
{ name: "hello.txt", data: "Hello, World!" },
{ name: "data/numbers.txt", data: "1 2 3 4 5" }
])

archive::zip_extract(data: Array<int>) -> Array<{name, data}>

Section titled “archive::zip_extract(data: Array<int>) -> Array<{name, data}>”

Extract a zip archive from a byte array. Returns an array of entry objects. Directory entries are skipped.

let entries = archive::zip_extract(zip_bytes)
for entry in entries {
print(f"{entry.name}: {entry.data.length} bytes")
}

archive::tar_create(entries: Array<{name, data}>) -> Array<int>

Section titled “archive::tar_create(entries: Array<{name, data}>) -> Array<int>”

Create a tar archive in memory from an array of entries.

let tar_bytes = archive::tar_create([
{ name: "readme.txt", data: "Hello from tar" }
])

archive::tar_extract(data: Array<int>) -> Array<{name, data}>

Section titled “archive::tar_extract(data: Array<int>) -> Array<{name, data}>”

Extract a tar archive from a byte array. Returns an array of entry objects. Directory entries are skipped.

let entries = archive::tar_extract(tar_bytes)
use std::core::archive
let entries = [
{ name: "src/main.shape", data: "fn main() { print(\"hello\") }" },
{ name: "README.txt", data: "My project" }
]
let zipped = archive::zip_create(entries)
let extracted = archive::zip_extract(zipped)
assert extracted.length == 2
  • compress — data compression
  • file — filesystem operations