A pure MoonBit RFC 3284 VCDIFF encoder, decoder, inspector, and CLI
Dependencies
moon add yangxixi00/moon_vcdiff@0.1.0///|
import {
"yangxixi00/moon_vcdiff" @vcdiff,
}let source = b"the original document"
let target = b"the revised document"
let delta = @vcdiff.encode(
source,
target,
@vcdiff.default_encode_options(),
)
let decoded = @vcdiff.decode(
source,
delta,
@vcdiff.default_decode_limits(),
)
assert_eq(decoded, target)
let summary = @vcdiff.inspect(delta)
println(summary.to_json())moon run cmd/main -- encode old.bin new.bin patch.vcdiff --profile balanced
moon run cmd/main -- decode old.bin patch.vcdiff restored.bin --profile service
moon run cmd/main -- inspect patch.vcdiff --format json
moon run cmd/main -- trace patch.vcdiff --format text
moon run cmd/main -- stats patch.vcdiff --format json
moon run cmd/main -- audit old.bin patch.vcdiff --max-output 64MiB
moon run cmd/main -- verify old.bin patch.vcdiff new.binmoon add yangxixi00/moon_vcdiff@0.1.0moon run cmd/main -- encode 旧文件.bin 新文件.bin 更新.vcdiff -p balanced
moon run cmd/main -- decode 旧文件.bin 更新.vcdiff 还原文件.bin -p service
moon run cmd/main -- inspect 更新.vcdiff -f json
moon run cmd/main -- verify 旧文件.bin 更新.vcdiff 新文件.binmoon fmt --check
moon check --target all --deny-warn
moon build --target all --deny-warn
moon test --target all --deny-warn
pwsh ./scripts/count-production-lines.ps1
moon package --frozenpub(all) suberror VcdiffError {
InvalidMagic(offset~ : Int)
UnsupportedVersion(offset~ : Int, version~ : Int)
UnsupportedFeature(offset~ : Int, feature~ : String)
TruncatedInput(offset~ : Int, needed~ : Int, available~ : Int)
InvalidVarint(offset~ : Int, reason~ : String)
IntegerOverflow(offset~ : Int)
InvalidHeader(offset~ : Int, reason~ : String)
InvalidWindow(offset~ : Int, reason~ : String)
InvalidInstruction(offset~ : Int, reason~ : String)
InvalidAddress(offset~ : Int, address~ : Int, limit~ : Int)
MissingSource(offset~ : Int)
ResourceLimit(offset~ : Int, resource~ : String, limit~ : Int)
LengthMismatch(offset~ : Int, expected~ : Int, actual~ : Int)
VerificationMismatch(offset~ : Int, expected_size~ : Int, actual_size~ : Int)
InvalidOption(option~ : String, reason~ : String)
Io(path~ : String, reason~ : String)
} derive(Eq, Debug)pub(all) struct AuditDiagnostic {
level : DiagnosticLevel
code : String
message : String
offset : Int
} derive(Eq, Debug)pub(all) struct AuditReport {
structurally_valid : Bool
decodable : Bool
decoded_size : Int
summary : DeltaSummary?
resources : ResourceEstimate
diagnostics : Array[AuditDiagnostic]
} derive(Eq, Debug)pub(all) struct CodeTableEntry {
first : CodeInstruction
second : CodeInstruction
} derive(Eq, Debug)fn DecodeLimits::new(max_output_size~ : Int, max_window_size~ : Int, max_windows~ : Int, max_instructions_per_window~ : Int) -> DecodeLimits raise VcdiffErrorpub(all) struct DecodeResult {
target : Bytes
summary : DeltaSummary
trace : DeltaTrace
} derive(Eq, Debug)pub(all) struct DeltaIndex {
file_size : Int
header_size : Int
target_size : Int
source_window_count : Int
target_window_count : Int
independent_window_count : Int
windows : Array[WindowIndexEntry]
} derive(Eq, Debug)pub(all) struct DeltaStatistics {
file_size : Int
target_size : Int
window_count : Int
header_bytes : Int
window_header_bytes : Int
data_bytes : Int
instruction_bytes : Int
address_bytes : Int
operations : InstructionStatistics
windows : Array[WindowStatistics]
} derive(Eq, Debug)pub(all) struct DeltaSummary {
file_size : Int
header_size : Int
window_count : Int
target_size : Int
data_size : Int
instruction_size : Int
address_size : Int
add_count : Int
run_count : Int
copy_count : Int
uses_source : Bool
uses_target : Bool
windows : Array[WindowSummary]
} derive(Eq, Debug)pub(all) struct DeltaTrace {
file_size : Int
window_count : Int
target_size : Int
instruction_count : Int
add_count : Int
run_count : Int
copy_count : Int
instructions : Array[TraceInstruction]
} derive(Eq, Debug)fn EncodeOptions::new(window_size~ : Int, minimum_match~ : Int, max_candidate_chain~ : Int, run_threshold~ : Int, enable_target_matches~ : Bool) -> EncodeOptions raise VcdiffErrorpub(all) struct EncodeResult {
delta : Bytes
summary : DeltaSummary
trace : DeltaTrace
} derive(Eq, Debug)pub(all) struct InstructionStatistics {
instruction_count : Int
add_count : Int
run_count : Int
copy_count : Int
add_bytes : Int
run_bytes : Int
copy_bytes : Int
literal_bytes : Int
maximum_instruction_size : Int
tiny_instructions : Int
small_instructions : Int
medium_instructions : Int
large_instructions : Int
copy_mode_counts : Array[Int]
} derive(Eq, Debug)pub(all) struct TraceInstruction {
window_index : Int
ordinal : Int
code_index : Int
code_offset : Int
code_slot : Int
kind : InstructionKind
size : Int
mode : Int
target_offset : Int
data_offset : Int
data_size : Int
address_offset : Int
address : Int
} derive(Eq, Debug)pub(all) struct WindowIndexEntry {
index : Int
file_offset : Int
encoded_size : Int
target_offset : Int
target_size : Int
source_kind : WindowSourceKind
source_position : Int
source_size : Int
data_offset : Int
instruction_offset : Int
address_offset : Int
} derive(Eq, Debug)pub(all) struct WindowStatistics {
window_index : Int
target_size : Int
delta_size : Int
data_size : Int
instruction_size : Int
address_size : Int
operations : InstructionStatistics
} derive(Eq, Debug)pub(all) struct WindowSummary {
index : Int
offset : Int
source_kind : WindowSourceKind
source_size : Int
source_position : Int
target_size : Int
delta_size : Int
data_size : Int
instruction_size : Int
address_size : Int
add_count : Int
run_count : Int
copy_count : Int
} derive(Eq, Debug)let DEFAULT_ADDRESS_MODE_COUNT : Intlet DEFAULT_NEAR_CACHE_SIZE : Intlet DEFAULT_SAME_CACHE_SIZE : Intfn decode_code_table_data(data : Bytes, near_size : Int, same_size : Int) -> Array[CodeTableEntry] raise VcdiffErrorfn decode_detailed(source : Bytes, delta : Bytes, limits : DecodeLimits) -> DecodeResult raise VcdiffErrorfn decode_range(source : Bytes, delta : Bytes, start : Int, end : Int, limits : DecodeLimits) -> Bytes raise VcdiffErrorfn decode_windows(source : Bytes, delta : Bytes, limits : DecodeLimits) -> Array[Bytes] raise VcdiffErrorfn default_code_table_data() -> Bytesfn encode_code_table_data(table : Array[CodeTableEntry], near_size : Int, same_size : Int) -> Bytes raise VcdiffErrorfn encode_detailed(source : Bytes, target : Bytes, options : EncodeOptions) -> EncodeResult raise VcdiffErrorfn inspect_code_table(table : Array[CodeTableEntry], near_size : Int, same_size : Int) -> CodeTableMetrics raise VcdiffErrorfn product_name() -> StringA pure MoonBit RFC 3284 VCDIFF encoder, decoder, inspector, and CLI
Dependencies