Seekable Zstandard archives and byte-range extraction in MoonBit
fn demo(input : Bytes) -> Bytes raise @seek.ArchiveError {
let packed = @seek.compress(input, frame_size=1024, checksums=true)
let archive = @seek.Archive::open(@seek.Source::from_bytes(packed))
archive.read_range(0L, input.length().min(32))
}moon run --target native cmd/moonseekzst -- pack app.log app.zst 1024
moon run --target native cmd/moonseekzst -- info app.zst
moon run --target native cmd/moonseekzst -- extract app.zst 1001 91 slice.bin --trace-reads$support = (Resolve-Path ../test-support).Path
python tools/acceptance.py --support $support --dependency-dir "$support/dependency-recovery" --work-dir "$env:TEMP/moonseekzst-acceptance"| 验证 | native | wasm-gc |
|---|---|---|
| 核心单测 | 13/13 | 13/13 |
| 官方归档 → 正式库 | 7/7 切片 | 7/7 切片 |
| 正式库 → 官方 Seekable 跨帧提取 | 91 字节一致 | 91 字节一致 |
| 正式库 → 普通 zstd -dc | 5,767 字节一致 | 5,767 字节一致 |
| 损坏归档 | 6 项打开拒绝、2 项读取拒绝 | 6 项打开拒绝、2 项读取拒绝 |
pub suberror ArchiveError {
InvalidIndex(String)
InvalidRange
InvalidFrame(Int, String)
ChecksumMismatch(Int)
LimitExceeded(String)
SourceError(String)
SinkError(String)
}pub struct Archive {
// private fields
}fn Archive::extract(self : Archive, offset : Int64, length : Int, decode : (BytesView, Int) -> Bytes raise, max_frame_bytes? : Int) -> Bytes raise ArchiveErrorfn Archive::read_range(self : Archive, offset : Int64, length : Int, max_frame_bytes? : Int) -> Bytes raise ArchiveErrorpub struct Source {
length : Int64
read_at : (Int64, Int) -> Bytes raise
}fn write_archive(source : Source, write : (Bytes) -> Unit raise ArchiveError, frame_size? : Int, checksums? : Bool) -> Unit raise ArchiveError