xet

package module
v0.0.0-...-76f69d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 8 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

XET Protocol (Go Implementation)

Go implementation of the XET content-addressable storage protocol for large-file transfer with chunk-level deduplication.

This project tracks:

The Rust implementation in xet-core is currently ahead of the draft in several areas, so this repository prioritizes compatibility with real xet-core behavior where needed.

Current Scope

Implemented in this repository:

  • Core hash / gearhash / merkle primitives
  • Shard and xorb encode/decode paths
  • Upload and download client workflows with streaming wrappers (upload from any io.ReadSeeker, download to an io.WriteSeeker or as io.ReadCloser streams)
  • Server storage backends: local filesystem, in-memory, or S3-compatible object stores, with optional presigned xorb download URLs
  • Mirror mode: full-cache middle layer bridging xet and plain hubs
  • Hugging Face token/LFS based integration helpers
  • Conformance and unit tests for key protocol paths

Compatibility Notes

  • This project aims to follow the draft spec where possible.
  • When draft and xet-core behavior diverge, practical interop with xet-core may take priority.
  • Test and conformance coverage is evolving with protocol and upstream changes.
  • Chunk boundaries, and therefore xet file hashes, follow the current xet-core chunker, which never cuts a chunk shorter than the 8 KiB minimum (xet-core#487, first shipped in hf-xet 1.1.10, September 2025). Earlier clients could occasionally cut a shorter chunk, so a file uploaded with hf-xet 1.1.9 or older — which includes many uploads made before 2026 — may be recorded upstream under a xet hash that differs from the one this implementation computes for the same bytes. The SHA-256 (LFS OID) is unaffected.

Benchmark Gate

Every pull request to master runs the Benchmark gate check (workflow) with benchgate: one CI job builds the pull request's merge result and the master commit it merges into, benchmarks both on that runner in alternating rounds, and fails on a confirmed regression.

The configuration is test/benchgate.json. A new benchmark in the xorb package is judged as it is; elsewhere, add it to a group's bench pattern or add a group.

How a regression is judged, which pull requests are measured and what to do when the check is red are in benchgate's README.

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

View Source
const (
	// Content-defined chunking parameters (Gearhash)
	TargetChunkSize = 65536  // 64 KiB
	MinChunkSize    = 8192   // 8 KiB
	MaxChunkSize    = 131072 // 128 KiB
	GearhashMask    = 0xFFFF000000000000

	// Merkle tree parameters
	MeanBranchingFactor = 4
	MinChildren         = 2
	MaxChildren         = 9

	// Xorb parameters
	MaxChunksPerXorb    = 8192
	MaxXorbSize         = 64 * 1024 * 1024 // 64 MiB maximum uncompressed chunk payload
	TargetChunksPerXorb = 1024
)

Algorithm Suite: XET-BLAKE3-GEARHASH-LZ4

Variables

This section is empty.

Functions

func ChunkData

func ChunkData(r io.Reader, fn func(offset int64, chunk []byte) error) error

ChunkData reads data from the provided reader and invokes fn for each chunk. Note: the chunk data passed to fn is only valid for the duration of the callback, so fn should copy it if it needs to retain it. The offset parameter indicates the cumulative byte offset of the chunk within the stream, which can be used for tracking progress or associating chunks with file offsets.

Types

type ChunkHash

type ChunkHash hash

ChunkHash identifies an individual content-defined chunk.

func ComputeChunkHash

func ComputeChunkHash(data []byte) ChunkHash

ComputeChunkHash computes the hash of a chunk using DATA_KEY

func ParseChunkHash

func ParseChunkHash(s string) (ChunkHash, error)

ParseChunkHash parses an XET hash string as a chunk hash.

func (ChunkHash) HMAC

func (h ChunkHash) HMAC(key [32]byte) ChunkHash

HMAC returns the keyed form of the chunk hash: a BLAKE3 keyed hash of the raw hash bytes, matching xet-core's MerkleHash::hmac. CAS servers key the chunk hashes in returned global-dedup shards with a per-shard key.

func (ChunkHash) String

func (h ChunkHash) String() string

type Chunker

type Chunker struct {
	// contains filtered or unexported fields
}

Chunker provides an iterator-like interface for chunking data from a reader using the Gearhash algorithm.

func NewChunker

func NewChunker(r io.Reader) *Chunker

NewChunker creates a new Chunker for the given reader. The returned Chunker can be used to iteratively read chunks of data that are determined by the Gearhash algorithm, which provides content-defined chunking for better deduplication and compression efficiency.

func (*Chunker) Chunk

func (c *Chunker) Chunk() (offset int64, chunk []byte, err error)

Chunk returns the offset of the next chunk and advances the internal state to the following chunk. When the end of the stream is reached, it returns io.EOF. The offset can be used to track the position of each chunk within the original data stream, which is useful for associating chunks with file offsets or for progress tracking during processing.

type FileHash

type FileHash hash

FileHash identifies a reconstructed file. It is intentionally a distinct type from ChunkHash so the two cannot be mixed accidentally.

func ComputeFileHash

func ComputeFileHash(chunkHashes []ChunkHash, chunkSizes []uint64) FileHash

ComputeFileHash computes the file hash from chunk hashes and sizes. Non-empty files apply an additional keyed hash step to the Merkle root; an empty file is represented directly by ZERO_HASH.

func ParseFileHash

func ParseFileHash(s string) (FileHash, error)

ParseFileHash parses an XET hash string as a file hash.

func (FileHash) String

func (h FileHash) String() string

type VerificationHash

type VerificationHash hash

VerificationHash identifies a term verification hash for a file reconstruction term.

func ComputeVerificationHash

func ComputeVerificationHash(chunkHashes []ChunkHash) VerificationHash

ComputeVerificationHash computes a term verification hash using VERIFICATION_KEY

func ParseVerificationHash

func ParseVerificationHash(s string) (VerificationHash, error)

ParseVerificationHash parses an XET hash string as a verification hash.

func (VerificationHash) String

func (h VerificationHash) String() string

type XorbHash

type XorbHash hash

XorbHash identifies a content-addressed xorb containing one or more chunks.

func ComputeXorbHash

func ComputeXorbHash(chunkHashes []ChunkHash, chunkSizes []uint64) XorbHash

ComputeXorbHash computes the xorb hash from chunk hashes and sizes

func ParseXorbHash

func ParseXorbHash(s string) (XorbHash, error)

ParseXorbHash parses an XET hash string as an xorb hash.

func (XorbHash) String

func (h XorbHash) String() string

Directories

Path Synopsis
Package auth defines the server-side authorization hook and a reference HMAC token issuer.
Package auth defines the server-side authorization hook and a reference HMAC token issuer.
hf
Package hf is the xet client for Hugging Face hub repositories.
Package hf is the xet client for Hugging Face hub repositories.
hf/hftest
Package hftest holds the recorded Hugging Face hub trace format: the redacted exchanges a tool made with a hub and the CAS it named, from which the regression tests model a private hub.
Package hftest holds the recorded Hugging Face hub trace format: the redacted exchanges a tool made with a hub and the CAS it named, from which the regression tests model a private hub.
cmd
xetc command
xetd command
internal
lru
pool
Package pool provides shared sync.Pool-backed buffers for hot paths.
Package pool provides shared sync.Pool-backed buffers for hot paths.
xorbmap
Package xorbmap caches read-only memory mappings of whole xorb files, reference-counted so an evicted mapping lives until its last reader closes.
Package xorbmap caches read-only memory mappings of whole xorb files, reference-counted so an evicted mapping lives until its last reader closes.
Package mirror implements the ingestion engine of a full-cache middle layer that sits between a hub upstream (huggingface.co, an HF mirror, modelscope.cn, ...) and downstream clients, bridging every combination of xet-capable and plain peers.
Package mirror implements the ingestion engine of a full-cache middle layer that sits between a hub upstream (huggingface.co, an HF mirror, modelscope.cn, ...) and downstream clients, bridging every combination of xet-capable and plain peers.
spool
Package spool handles the protocol-agnostic spooling of downloaded bytes on the way into local storage: an append-only, tail-readable spool that buffers in memory and spills to a file named by content identity, and the verify-and-ingest step into storage.
Package spool handles the protocol-agnostic spooling of downloaded bytes on the way into local storage: an append-only, tail-readable spool that buffers in memory and spills to a file named by content identity, and the verify-and-ingest step into storage.
hf
Package hf serves the Hugging Face hub front end of a mirror: hub-style resolve requests are answered from the local cache (ingesting on miss through the mirror engine), the token endpoints hand downstream clients their CAS credential, and tree listings are rewritten so xet clients stay on the mirror.
Package hf serves the Hugging Face hub front end of a mirror: hub-style resolve requests are answered from the local cache (ingesting on miss through the mirror engine), the token endpoints hand downstream clients their CAS credential, and tree listings are rewritten so xet clients stay on the mirror.
internalapi
Package internalapi serves non-CAS management endpoints with Read or Write permission.
Package internalapi serves non-CAS management endpoints with Read or Write permission.
local
Package local implements storage.Storage on a filesystem below the base directory given to NewStorage.
Package local implements storage.Storage on a filesystem below the base directory given to NewStorage.
memory
Package memory implements storage.Storage over process memory, for tests and ephemeral servers.
Package memory implements storage.Storage over process memory, for tests and ephemeral servers.
s3
Package s3 implements storage.Storage over an S3-compatible object store with the local backend's layout under an optional key prefix.
Package s3 implements storage.Storage over an S3-compatible object store with the local backend's layout under an optional key prefix.
storagetest
Package storagetest runs the backend-independent storage tests against a Backend.
Package storagetest runs the backend-independent storage tests against a Backend.
test
benchgate module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址