Read, inspect and compare ar archives in MoonBit
Dependencies
git clone https://github.com/xmyd0915/moonar.git
cd moonar
moon update
moon run cmd/main --target native -- inspect examples/data/bundle-before.a0 regular 11 "config.txt"
1 regular 3 "assets.bin"moon run cmd/main --target native -- diff examples/data/bundle-before.a examples/data/bundle-time.a --json| 场景 | 输入与操作 | 可观察的结果 |
|---|---|---|
| 检查构建产物 | 用 inspect 查看归档,用 check 检查截断样本 | 列出成员;损坏样本返回错误代码和字节偏移 |
| 排查构建差异 | 用 diff 分别比较时间戳变化和内容变化的样本 | 区分 metadata_changed 与 payload_changed |
| 读取 Debian 包外层 | 通过公共库接口读取示例 .deb | 找到三个外层成员,读取 debian-binary 的 2.0 标记 |
moon run cmd/main --target native -- diff before.a after.a --logical --jsoninspect FILE [--json] 列出物理记录、大小、类型和名称
check FILE [--json] 检查受支持的容器结构
diff BEFORE AFTER [--json] [--logical] 比较归档字节、成员或逻辑映射
--help | --version| 命令 | 退出码 0 | 退出码 1 | 退出码 2 |
|---|---|---|---|
| inspect / check | 成功 | 容器无效或超出限制 | 参数或文件读取失败 |
| diff | 字节完全相同 | 字节不同 | 参数、读取或任一输入解析失败 |
| diff --logical | 内容、已配对元数据、顺序、索引映射与存在性相同,且配对无歧义 | 任一维度不同或配对有歧义 | 参数、读取或任一输入解析失败 |
moon add xmyd0915/moonar@0.2.0import {
"xmyd0915/moonar" @ar,
}fn inspect_bytes(input : Bytes) -> Unit {
match @ar.parse(input) {
Ok(archive) => {
for i = 0; i < archive.member_count(); i = i + 1 {
let entry = archive.get_member(i).unwrap()
println("\{entry.name_hex()}: \{entry.size} bytes")
}
}
Err(error) => println("\{error.code} at byte \{error.offset}")
}
}moon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warn
moon build --target native --deny-warn
python tools/examples.py --moonar _build/native/debug/build/cmd/main/main.exe
moon run examples/read_deb --target nativepython tools/verify_archives.py --moonar _build/native/debug/build/cmd/main/main.exe --require-llvmpub(all) struct Comparison {
bytes_equal : Bool
order_changed : Bool
changes : Array[MemberChange]
ambiguities : Array[MatchAmbiguity]
} derive(Eq, Debug)pub(all) struct LogicalComparison {
bytes_equal : Bool
content_equal : Bool
metadata_changed : Bool
order_changed : Bool
symbols_equal : Bool
symbol_index_presence_changed : Bool
changes : Array[MemberChange]
ambiguities : Array[MatchAmbiguity]
} derive(Eq, Debug)pub(all) struct MatchAmbiguity {
name : Bytes
member_kind : MemberKind
before_indices : Array[Int]
after_indices : Array[Int]
} derive(Eq, Debug)pub(all) struct Member {
name : Bytes
kind : MemberKind
header_offset : Int
data_offset : Int
size : Int
stored_size : Int
metadata : Metadata
} derive(Eq, Debug)pub(all) struct MemberChange {
change : ChangeKind
name : Bytes
member_kind : MemberKind
occurrence : Int
before_index : Int?
after_index : Int?
payload_changed : Bool
metadata_changed : Bool
} derive(Eq, Debug)fn parse(input : Bytes, max_members? : Int, max_bytes? : Int, max_name_bytes? : Int, max_symbols? : Int, max_symbol_name_bytes? : Int) -> Result[Archive, ParseError]Install
Download zipRead, inspect and compare ar archives in MoonBit
Dependencies