packfile

package
v4.0.0-rc1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package packfile implements a encoder/decoder of packfile format

Index

Constants

View Source
const (
	// VersionSupported is the packfile version supported by this parser.
	VersionSupported uint32 = 2
)

Variables

View Source
var (
	// ErrMaxObjectsLimitReached is returned by Decode when the number
	// of objects in the packfile is higher than
	// Decoder.MaxObjectsLimit.
	ErrMaxObjectsLimitReached = NewError("max. objects limit reached")
	// ErrInvalidObject is returned by Decode when an invalid object is
	// found in the packfile.
	ErrInvalidObject = NewError("invalid git object")
	// ErrPackEntryNotFound is returned by Decode when a reference in
	// the packfile references and unknown object.
	ErrPackEntryNotFound = NewError("can't find a pack entry")
	// ErrZLib is returned by Decode when there was an error unzipping
	// the packfile contents.
	ErrZLib = NewError("zlib reading error")
	// ErrCannotRecall is returned by RecallByOffset or RecallByHash if the object
	// to recall cannot be returned.
	ErrCannotRecall = NewError("cannot recall object")
	// ErrNonSeekable is returned if a NewDecoder is used with a non-seekable
	// reader and without a core.ObjectStorage or ReadObjectAt method is called
	// without a seekable scanner
	ErrNonSeekable = NewError("non-seekable scanner")
)
View Source
var (
	// ErrEmptyPackfile is returned by ReadHeader when no data is found in the packfile
	ErrEmptyPackfile = NewError("empty packfile")
	// ErrBadSignature is returned by ReadHeader when the signature in the packfile is incorrect.
	ErrBadSignature = NewError("malformed pack file signature")
	// ErrUnsupportedVersion is returned by ReadHeader when the packfile version is
	// different than VersionSupported.
	ErrUnsupportedVersion = NewError("unsupported packfile version")
	// ErrSeekNotSupported returned if seek is not support
	ErrSeekNotSupported = NewError("not seek support")
)

Functions

func ApplyDelta

func ApplyDelta(target, base core.Object, delta []byte) error

ApplyDelta writes to taget the result of applying the modification deltas in delta to base.

func PatchDelta

func PatchDelta(src, delta []byte) []byte

PatchDelta returns the result of applying the modification deltas in delta to src.

Types

type Decoder

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

Decoder reads and decodes packfiles from an input stream.

func NewDecoder

func NewDecoder(s *Scanner, o core.ObjectStorage) (*Decoder, error)

NewDecoder returns a new Decoder that reads from r.

func (*Decoder) CRCs

func (d *Decoder) CRCs() map[core.Hash]uint32

CRCs returns the CRC-32 for each objected read

func (*Decoder) Close

func (d *Decoder) Close() error

Close close the Scanner, usually this mean that the whole reader is read and discarded

func (*Decoder) Decode

func (d *Decoder) Decode() (checksum core.Hash, err error)

Decode reads a packfile and stores it in the value pointed to by s.

func (*Decoder) Offsets

func (d *Decoder) Offsets() map[core.Hash]int64

Offsets returns the objects read offset

func (*Decoder) ReadObject

func (d *Decoder) ReadObject() (core.Object, error)

ReadObject reads a object from the stream and return it

func (*Decoder) ReadObjectAt

func (d *Decoder) ReadObjectAt(offset int64) (core.Object, error)

ReadObjectAt reads an object at the given location

func (*Decoder) SetOffsets

func (d *Decoder) SetOffsets(offsets map[core.Hash]int64)

SetOffsets sets the offsets, required when using the method ReadObjectAt, without decoding the full packfile

type Error

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

Error specifies errors returned during packfile parsing.

func NewError

func NewError(reason string) *Error

NewError returns a new error.

func (*Error) AddDetails

func (e *Error) AddDetails(format string, args ...interface{}) *Error

AddDetails adds details to an error, with additional text.

func (*Error) Error

func (e *Error) Error() string

Error returns a text representation of the error.

type Format

type Format int

Format specifies if the packfile uses ref-deltas or ofs-deltas.

const (
	UnknownFormat Format = iota
	OFSDeltaFormat
	REFDeltaFormat
)

Possible values of the Format type.

type ObjectHeader

type ObjectHeader struct {
	Type            core.ObjectType
	Offset          int64
	Length          int64
	Reference       core.Hash
	OffsetReference int64
}

ObjectHeader contains the information related to the object, this information is collected from the previous bytes to the content of the object.

type Scanner

type Scanner struct {

	// lsSeekable says if this scanner can do Seek or not, to have a Scanner
	// seekable a r implementing io.Seeker is required
	IsSeekable bool
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new Scanner based on a reader, if the given reader implements io.ReadSeeker the Scanner will be also Seekable

func (*Scanner) Checksum

func (s *Scanner) Checksum() (core.Hash, error)

Checksum returns the checksum of the packfile

func (*Scanner) Close

func (s *Scanner) Close() error

Close reads the reader until io.EOF

func (*Scanner) Header

func (s *Scanner) Header() (version, objects uint32, err error)

Header reads the whole packfile header (signature, version and object count). It returns the version and the object count and performs checks on the validity of the signature and the version fields.

func (*Scanner) NextObject

func (s *Scanner) NextObject(w io.Writer) (written int64, crc32 uint32, err error)

NextObject writes the content of the next object into the reader, returns the number of bytes written, the CRC32 of the content and an error, if any

func (*Scanner) NextObjectHeader

func (s *Scanner) NextObjectHeader() (*ObjectHeader, error)

NextObjectHeader returns the ObjectHeader for the next object in the reader

func (*Scanner) Seek

func (s *Scanner) Seek(offset int64) (previous int64, err error)

Seek sets a new offset from start, returns the old position before the change

Jump to

Keyboard shortcuts

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