xet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package xet validates the public Hugging Face Xet chunk and shard wire formats.

Index

Constants

View Source
const (
	MaxChunk       = 128 << 10
	MaxXorb        = 64 << 20
	MaxEncodedXorb = 80 << 20
	MaxChunks      = 8192
)
View Source
const MaxShard = 64 << 20

Variables

View Source
var ErrInvalid = errors.New("invalid Xet content")

Functions

func EncodeChunks

func EncodeChunks(chunks [][]byte) ([]byte, error)

EncodeChunks writes the uncompressed transfer representation, suitable for a signed byte-range response. A reconstruction never needs the xorb footer.

Types

type Chunk

type Chunk struct {
	Hash  Hash
	Data  []byte
	Start int
	End   int
}

type File

type File struct {
	Hash     Hash
	SHA256   string
	Segments []Segment
	Verified bool
}

type Hash

type Hash [32]byte

Hash is the binary Merkle hash. Xet's textual form reverses each uint64 word.

func Aggregate

func Aggregate(parts []HashPart) Hash

func DataHash

func DataHash(data []byte) Hash

func FileHash

func FileHash(parts []HashPart) Hash

func ParseHash

func ParseHash(s string) (Hash, bool)

func RangeHash

func RangeHash(parts []HashPart) Hash

func (Hash) String

func (h Hash) String() string

type HashPart

type HashPart struct {
	Hash Hash
	Size uint64
}

HashPart carries the chunk's uncompressed length, which is part of its parent hash.

func Parts

func Parts(chunks []Chunk) []HashPart

type Segment

type Segment struct {
	Xorb         Hash
	Size         uint32
	Start        uint32
	End          uint32
	Verification Hash
}

type Shard

type Shard struct {
	Files []File
	Xorbs []ShardXorb
}

func ParseShard

func ParseShard(data []byte) (Shard, error)

ParseShard accepts the version-2 MDB wire format. Every section is bounded before entry counts are used; upload-only lookup tables are never trusted.

type ShardXorb

type ShardXorb struct {
	Hash        Hash
	Size        uint32
	EncodedSize uint32
	Chunks      []HashPart
}

type Xorb

type Xorb struct {
	Hash   Hash
	Chunks []Chunk
}

func ParseXorb

func ParseXorb(data []byte, want string) (Xorb, error)

ParseXorb authenticates every chunk, both boundary tables, and the root hash before the object can be referenced by a file reconstruction.

Jump to

Keyboard shortcuts

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