Safe cpio parsing, streaming, deterministic writing, and CLI extraction.
Dependencies
moon add oilleelssq-wq/moon-cpio///|
import {
"oilleelssq-wq/moon-cpio" @cpio,
}
///|
fn inspect_archive(bytes : Bytes) -> Unit raise {
let archive = @cpio.parse_newc(bytes).unwrap()
for entry in archive.entries {
println("\{entry.name}: \{entry.data.length()} bytes")
}
}moon run cmd/main -- list --format auto archive.cpio
moon run cmd/main -- validate --format auto archive.cpio
moon run cmd/main -- extract --format auto archive.cpio ./outputmoon check
moon test
moon fmtpub(all) struct BinaryArchive {
variant : BinaryVariant
byte_order : BinaryByteOrder
entries : Array[BinaryEntry]
} derive(Eq, Debug)pub(all) struct BinaryEntry {
name : String
name_bytes : Bytes
header : BinaryHeader
data : Bytes
} derive(Eq, Debug)pub(all) struct BinaryHeader {
variant : BinaryVariant
dev : UInt64
ino : UInt64
mode : UInt64
uid : UInt64
gid : UInt64
nlink : UInt64
rdev : UInt64
mtime : UInt64
file_size : UInt64
name_size : UInt64
} derive(Eq, Debug)pub(all) enum CpioError {
TruncatedHeader(Int)
UnsupportedMagic(Int)
InvalidHex(Int)
InvalidOctal(Int)
InvalidNameSize(Int)
TruncatedName(Int)
MissingNameTerminator(Int)
EmbeddedNul(Int)
InvalidUtf8Name(Int)
TruncatedData(Int)
ChecksumMismatch(Int, UInt64, UInt64)
MixedFormats(Int)
InvalidTrailer(Int)
} derive(Eq, Debug)pub(all) struct Header {
format : NewcFormat
ino : UInt64
mode : UInt64
uid : UInt64
gid : UInt64
nlink : UInt64
mtime : UInt64
file_size : UInt64
dev_major : UInt64
dev_minor : UInt64
rdev_major : UInt64
rdev_minor : UInt64
name_size : UInt64
check : UInt64
} derive(Eq, Debug)fn NewcWriteEntry::new(name : String, data : Bytes, mode? : UInt64, uid? : UInt64, gid? : UInt64, mtime? : UInt64) -> NewcWriteEntrypub(all) struct StreamEntry {
name : String
name_bytes : BytesView
header : StreamHeader
data : BytesView
} derive(Eq, Debug)fn newc_checksum(data : BytesView) -> UInt64fn parse_binary_new(input : Bytes, byte_order : BinaryByteOrder) -> Result[BinaryArchive, CpioError]fn stream_entries(input : Bytes, format : CpioFormat, on_entry : (StreamEntry) -> Unit) -> Result[Unit, CpioError]fn write_newc(entries : ArrayView[NewcWriteEntry], format? : NewcFormat) -> Result[Bytes, WriteError]Install
Download zipSafe cpio parsing, streaming, deterministic writing, and CLI extraction.
Dependencies