bit_pack

Git packfile encoder/decoder + index (gix-pack equivalent)

git
pack
packfile
index
moon add mizchi/bit_pack@0.46.4
Download zip
Author
Version
0.46.4
License
Apache-2.0
Last updated
4 days ago
Downloads
513
README

#
apply_delta

fn apply_delta(base : Bytes, delta : Bytes) -> Bytes raise
GitError

#
build_delta_pub

fn build_delta_pub(base : Bytes, target : Bytes) -> Bytes

#
build_pack_index

fn build_pack_index(pack : Bytes, hash_size? : Int) -> Bytes raise
GitError

Build a pack index (v2) from packfile bytes.

#
build_pack_index_from_objects

fn build_pack_index_from_objects(pack : Bytes, objects : Array[
PackObject
], hash_size? : Int) -> Bytes raise
GitError

Build a pack index (v2) from packfile bytes and parsed objects. Uses cached metadata (id, offset, crc32) from PackObject when available. Falls back to re-parsing the pack if metadata is missing.

#
build_reverse_index

fn build_reverse_index(pack : Bytes, objects : Array[
PackObject
]) -> Bytes raise
GitError

Build a reverse index (RIDX version 1) from packfile bytes and parsed objects. Format: magic("RIDX") + version(1) + hash_id(1) + position_table + pack_checksum + file_checksum The position_table maps from pack offset order to index position.

#
crc32_range

fn crc32_range(data : Bytes, start : Int, end : Int) -> UInt raise
GitError

#
create_blob_packfile

fn create_blob_packfile(content : Bytes, hash_size? : Int) -> Bytes

Create a packfile containing a single blob

#
create_commit_packfile

fn create_commit_packfile(blob_content : Bytes, filename : String, commit :
Commit
) -> (
ObjectId
, Bytes)

Create a packfile with blob, tree, and commit

#
create_packfile

fn create_packfile(objects : Array[
PackObject
], hash_size? : Int) -> Bytes

Create a packfile from a list of objects Format: [PACK] 4 bytes magic [version] 4 bytes (big-endian, always 2) [object count] 4 bytes (big-endian) [...objects...] variable [hash trailer] 20 or 32 bytes

#
create_packfile_with_delta

fn create_packfile_with_delta(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, hash_size? : Int) -> Bytes

Create a packfile from a list of objects with a chosen delta mode

#
create_packfile_with_delta_stats

fn create_packfile_with_delta_stats(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, hash_size? : Int) -> (Bytes, Int)

Create a packfile with delta statistics (delta object count)

#
create_packfile_with_delta_stats_compression

fn create_packfile_with_delta_stats_compression(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, compression :
PackCompression
, hash_size? : Int) -> (Bytes, Int)

Create a packfile with delta statistics and compression mode

#
create_packfile_with_delta_stats_compression_reuse

fn create_packfile_with_delta_stats_compression_reuse(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, compression :
PackCompression
, reuse_only : Bool, max_depth : Int, window : Int, hash_size? : Int) -> (Bytes, Int)

Create a packfile with delta stats, optional delta reuse, and depth limit

#
create_packfile_with_delta_stats_compression_reuse_and_metadata

fn create_packfile_with_delta_stats_compression_reuse_and_metadata(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, compression :
PackCompression
, reuse_only : Bool, max_depth : Int, window : Int, hash_size? : Int) -> (Bytes, Int, Array[
PackObject
])

Create a packfile and retain the index metadata collected while writing.

#
create_packfiles_with_size_limit

fn create_packfiles_with_size_limit(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, compression :
PackCompression
, reuse_only : Bool, max_depth : Int, size_limit : Int64, window : Int, hash_size? : Int) -> (Array[Bytes], Int)

Create multiple packfiles respecting a size limit. Objects are written one by one; when adding an object would cause the pack (including the hash trailer) to reach or exceed size_limit, the current pack is finalized and a new one is started. The first object in each pack is always written regardless of size.

#
create_packfiles_with_size_limit_and_metadata

fn create_packfiles_with_size_limit_and_metadata(objects : Array[
PackObject
], delta_mode :
PackDeltaMode
, compression :
PackCompression
, reuse_only : Bool, max_depth : Int, size_limit : Int64, window : Int, hash_size? : Int) -> (Array[(Bytes, Array[
PackObject
])], Int)

Create size-limited packfiles and retain index metadata for every entry.

#
decode_type_and_size_at

fn decode_type_and_size_at(data : Bytes, start : Int) -> (Int, Int, Int) raise
GitError

Decode packfile object header and return (type_id, size, next_offset).

#
encode_type_and_size

fn encode_type_and_size(obj_type : Int, size : Int, result : Array[Byte]) -> Unit

Encode type and size in Git's variable-length format

#
generate_commit_packfile

fn generate_commit_packfile() -> (
ObjectId
, Bytes)

#
generate_test_packfile

fn generate_test_packfile() -> Bytes

#
hex_dump

fn hex_dump(data : Bytes) -> String

Print packfile as hex dump for debugging

#
max_delta_chain_length

fn max_delta_chain_length(data : Bytes, hash_size? : Int) -> Int raise
GitError

Compute the maximum delta chain length in a packfile

#
packfile_type_to_object_type

fn packfile_type_to_object_type(type_id : Int) ->
ObjectType
raise
GitError

Convert packfile type id to ObjectType.

#
parse_packfile

fn parse_packfile(data : Bytes, verify_checksum? : Bool, hash_size? : Int) -> Array[
PackObject
] raise
GitError

Parse a packfile into objects.

#
parse_packfile_stream

fn parse_packfile_stream(data : Bytes, emit : (
PackObject
) -> Unit, verify_checksum? : Bool, hash_size? : Int) -> Unit raise
GitError

Parse a packfile and emit resolved objects (order not guaranteed).

#
parse_packfile_stream_with_bases

fn parse_packfile_stream_with_bases(data : Bytes, bases : Array[
PackObject
], emit : (
PackObject
) -> Unit, verify_checksum? : Bool, hash_size? : Int) -> Unit raise
GitError

Parse a packfile with base objects and emit resolved objects.

#
parse_packfile_with_bases

fn parse_packfile_with_bases(data : Bytes, bases : Array[
PackObject
], verify_checksum? : Bool, hash_size? : Int) -> Array[
PackObject
] raise
GitError

Parse a packfile with preloaded base objects (for thin packs).

#
read_ofs_delta_offset

fn read_ofs_delta_offset(data : Bytes, start : Int) -> (Int, Int) raise
GitError

#
read_ref_delta_id

fn read_ref_delta_id(data : Bytes, start : Int, hash_size? : Int) -> (String, Int) raise
GitError

#
write_pack_and_index

fn write_pack_and_index(fs : &
FileSystem
, git_dir : String, pack : Bytes, verify_checksum? : Bool) -> Unit raise
GitError

Write a packfile and build its index in one step. Avoids the need for callers to parse + write separately.

#
write_pack_index

fn write_pack_index(fs : &
FileSystem
, idx_path : String, pack : Bytes) -> Unit raise
GitError

Write a pack index to the filesystem.

#
write_pack_index_from_objects

fn write_pack_index_from_objects(fs : &
FileSystem
, idx_path : String, pack : Bytes, objects : Array[
PackObject
]) -> Unit raise
GitError

Write a pack index using pre-parsed objects.

#
write_pack_index_from_objects_versioned

fn write_pack_index_from_objects_versioned(fs : &
FileSystem
, idx_path : String, pack : Bytes, objects : Array[
PackObject
], version : Int, off64_threshold : Int64?) -> Unit raise
GitError

Write a pack index using pre-parsed objects with specific version.

#
write_packfile_with_index

fn write_packfile_with_index(fs : &
FileSystem
, git_dir : String, pack : Bytes, objects : Array[
PackObject
]) -> Unit raise
GitError

Write a packfile and its index under .git/objects/pack.

#
write_packfile_with_index_async

async fn[FS :
AsyncFileSystem
] write_packfile_with_index_async(fs : FS, git_dir : String, pack : Bytes, objects : Array[
PackObject
]) -> Unit raise
GitError

Asynchronous counterpart to write_packfile_with_index.

#
write_reverse_index

fn write_reverse_index(fs : &
FileSystem
, rev_path : String, pack : Bytes, objects : Array[
PackObject
]) -> Unit raise
GitError

Write a reverse index (.rev) file to the filesystem.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io