pack

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackVersion uint32 = 'Z'
	NoEntries   uint32 = 0
)
View Source
const (
	HashDigestSize = plumbing.HASH_DIGEST_SIZE
)
View Source
const (
	IndexVersionCurrent = 'Z'
)

Variables

View Source
var (

	// ErrShortFanout is an error representing situations where the entire
	// fanout table could not be read, and is thus too short.
	ErrShortFanout = fmt.Errorf("zeta: too short fanout table")
)

Functions

func EntriesSort

func EntriesSort(o objects)

EntriesSort sorts a slice of write index in increasing order.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns whether a given error represents a missing object in the index.

func NewPacks

func NewPacks(db string) (Set, Packs, error)

Types

type Encoder

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

func NewEncoder

func NewEncoder(fd *os.File, entries uint32) (*Encoder, error)

func (*Encoder) Name

func (e *Encoder) Name() string

func (*Encoder) Write

func (e *Encoder) Write(oid plumbing.Hash, size uint32, r io.Reader, modification int64) (err error)

func (*Encoder) WriteModification

func (e *Encoder) WriteModification(fd *os.File) error

func (*Encoder) WriteTrailer

func (e *Encoder) WriteTrailer() error

type Entry

type Entry struct {
	Hash         plumbing.Hash
	CRC32        uint32
	Offset       uint64
	Modification uint64
}

type Index

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

Index stores information about the location of objects in a corresponding packfile.

func DecodeIndex

func DecodeIndex(r io.ReaderAt) (*Index, error)

DecodeIndex decodes an index whose underlying data is supplied by "r".

DecodeIndex reads only the header and fanout table, and does not eagerly parse index entries.

If there was an error parsing, it will be returned immediately.

func (*Index) Close

func (i *Index) Close() error

Close closes the packfile index if the underlying data stream is closeable. If so, it returns any error involved in closing.

func (*Index) Count

func (i *Index) Count() int

Count returns the number of objects in the packfile.

func (*Index) Entry

func (i *Index) Entry(name plumbing.Hash) (*IndexEntry, error)

Entry returns an entry containing the offset of a given BLAKE3 "name".

Entry operates in O(log(n))-time in the worst case, where "n" is the number of objects that begin with the first byte of "name".

If the entry cannot be found, (nil, ErrNotFound) will be returned. If there was an error searching for or parsing an entry, it will be returned as (nil, err).

Otherwise, (entry, nil) will be returned.

func (*Index) PackedObjects

func (i *Index) PackedObjects(recv RecvFunc) error

func (*Index) Search

func (i *Index) Search(name plumbing.Hash) (oid plumbing.Hash, error error)

type IndexEntry

type IndexEntry struct {
	Pos int64
	// PackOffset is the number of bytes before the associated object in a
	// packfile.
	PackOffset uint64
}

IndexEntry specifies data encoded into an entry in the pack index.

type IndexVersion

type IndexVersion interface {
	// Name returns the name of the object located at the given offset "at",
	// in the Index file "idx".
	//
	// It returns an error if the object at that location could not be
	// parsed.
	Name(idx *Index, at int64) (plumbing.Hash, error)

	// Entry parses and returns the full *IndexEntry located at the offset
	// "at" in the Index file "idx".
	//
	// If there was an error parsing the IndexEntry at that location, it
	// will be returned.
	Entry(idx *Index, at int64) (*IndexEntry, error)
	// PackedObjects
	PackedObjects(idx *Index, recv RecvFunc) error

	// Width returns the number of bytes occupied by the header of a
	// particular index version.
	Width() int64
}

type IndexZ

type IndexZ struct {
}

IndexZ implements IndexVersion for packfiles.

func (*IndexZ) Entry

func (v *IndexZ) Entry(idx *Index, at int64) (*IndexEntry, error)

Entry implements IndexVersion.Entry for v2 packfiles by parsing and returning the IndexEntry specified at the offset "at" in the given index file.

func (*IndexZ) Name

func (v *IndexZ) Name(idx *Index, at int64) (oid plumbing.Hash, err error)

Name implements IndexVersion.Name by returning the 32 byte BLAKE3 object name for the given entry at offset "at" in the v2 index file "idx".

func (*IndexZ) PackedObjects

func (v *IndexZ) PackedObjects(idx *Index, recv RecvFunc) error

func (*IndexZ) Width

func (v *IndexZ) Width() int64

Width implements IndexVersion.Width() by returning the number of bytes that v2 packfile index header occupy.

type Packfile

type Packfile struct {
	// Version is the version of the packfile.
	Version uint32
	// Objects is the total number of objects in the packfile.
	Objects uint32
	// contains filtered or unexported fields
}

Packfile encapsulates the behavior of accessing an unpacked representation of all of the objects encoded in a single packfile.

func DecodePackfile

func DecodePackfile(r io.ReaderAt) (*Packfile, error)

DecodePackfile opens the packfile given by the io.ReaderAt "r" for reading. It does not apply any delta-base chains, nor does it do reading otherwise beyond the header.

If the header is malformed, or otherwise cannot be read, an error will be returned without a corresponding packfile.

func (*Packfile) Close

func (p *Packfile) Close() error

Close closes the packfile if the underlying data stream is closeable. If so, it returns any error involved in closing.

func (*Packfile) Exists

func (p *Packfile) Exists(name plumbing.Hash) error

func (*Packfile) Object

func (p *Packfile) Object(name plumbing.Hash) (*SizeReader, error)

func (*Packfile) Search

func (p *Packfile) Search(name plumbing.Hash) (oid plumbing.Hash, err error)

type Packs

type Packs []*Packfile

func (Packs) PackedObjects

func (ps Packs) PackedObjects(recv RecvFunc) error

type RecvFunc

type RecvFunc func(oid plumbing.Hash, modification int64) error

type Scanner

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

func NewScanner

func NewScanner(root string) (*Scanner, error)

func (*Scanner) Close

func (s *Scanner) Close() error

Open implements the storage.Storage.Open interface.

func (*Scanner) Exists

func (s *Scanner) Exists(name plumbing.Hash) error

check object exists

func (*Scanner) Names

func (s *Scanner) Names() []string

func (*Scanner) Open

func (s *Scanner) Open(oid plumbing.Hash) (r io.ReadCloser, err error)

Open implements the storage.Storage.Open interface.

func (*Scanner) PackedObjects

func (s *Scanner) PackedObjects(recv RecvFunc) error

func (*Scanner) Search

func (s *Scanner) Search(prefix plumbing.Hash) (plumbing.Hash, error)

type Set

type Set interface {
	Object(name plumbing.Hash) (*SizeReader, error)
	Exists(name plumbing.Hash) error
	Search(prefix plumbing.Hash) (plumbing.Hash, error)
	Close() error
}

func NewSets

func NewSets(db string) (Set, error)

NewSets

type SizeReader

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

SizeReader transforms an io.ReaderAt into an io.Reader by beginning and advancing all reads at the given offset.

func NewSizeReader

func NewSizeReader(r io.ReaderAt, offset int64, size int64) *SizeReader

func (*SizeReader) Close

func (r *SizeReader) Close() error

close

func (*SizeReader) Read

func (r *SizeReader) Read(p []byte) (n int, err error)

Read implements io.Reader.Read by reading into the given []byte, "p" from the last known offset provided to the OffsetReaderAt.

It returns any error encountered from the underlying data stream, and advances the reader forward by "n", the number of bytes read from the underlying data stream.

func (*SizeReader) Size

func (r *SizeReader) Size() int64

type Storage

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

Storage implements the storage.Storage interface.

func NewStorage

func NewStorage(root string) (*Storage, error)

NewStorage returns a new storage object based on a pack set.

func (*Storage) Close

func (f *Storage) Close() error

Open implements the storage.Storage.Open interface.

func (*Storage) Exists

func (f *Storage) Exists(name plumbing.Hash) error

check object exists

func (*Storage) Open

func (f *Storage) Open(oid plumbing.Hash) (r io.ReadCloser, err error)

Open implements the storage.Storage.Open interface.

func (*Storage) Search

func (f *Storage) Search(prefix plumbing.Hash) (oid plumbing.Hash, err error)

type UnsupportedVersionErr

type UnsupportedVersionErr struct {
	// Got is the unsupported version that was detected.
	Got uint32
}

UnsupportedVersionErr is a type implementing 'error' which indicates a the presence of an unsupported packfile version.

func (*UnsupportedVersionErr) Error

func (u *UnsupportedVersionErr) Error() string

Error implements 'error.Error()'.

type Writer

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

func NewWriter

func NewWriter(packDir string, entries uint32) (*Writer, error)

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Write

func (w *Writer) Write(oid plumbing.Hash, size uint32, r io.Reader, modification int64) (err error)

func (*Writer) WriteTrailer

func (w *Writer) WriteTrailer() error

Jump to

Keyboard shortcuts

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