archive/tar
lib/archive/tar.vklib/archive/tar.vk
Pure-Veko POSIX USTAR .tar and .tar.gz archive codec.
Enforces path confinement (rejecting .., leading /, \, and NUL bytes) and
verifies USTAR header checksums. Zero capabilities required.
TarEntry = struct { path str, data bytes, mode i64 = ..., mtime i64 = ... }
Single file entry stored in a .tar / .tar.gz archive.
pack = fn [entries block[TarEntry]] bytes
Packs entries into a POSIX USTAR .tar archive.
Executable Example
use [tar = archive/tar]
raw = tar/pack [
tar/TarEntry { path = 'hello.txt', data = bytes/from-str 'hello tar' }
tar/TarEntry { path = 'sub/a.vk', data = bytes/from-str '1 + 2' }
]
out = tar/unpack raw
if (len out) != 2 or out[0].path != 'hello.txt' or (bytes/to-str out[1].data) != '1 + 2' [
err 'tar roundtrip'
] else [ .ok ]
unpack = fn [raw bytes] block[TarEntry]
Unpacks a POSIX USTAR .tar archive, verifying header checksums and path confinement.
pack-gz = fn [entries block[TarEntry]] bytes
Packs entries into a gzip-compressed .tar.gz archive.
Executable Example
use [tar = archive/tar]
gz = tar/pack-gz [ tar/TarEntry { path = 'doc.txt', data = bytes/from-str 'veko tar.gz!' } ]
es = tar/unpack-gz gz
if (len es) != 1 or (bytes/to-str es[0].data) != 'veko tar.gz!' [ err 'tar.gz' ] else [ .ok ]