pack

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Signature  = append([]byte("ndpk"), []byte{0x01, 0xff, 0x00}...)
	Terminator = []byte{0xff, 0x00, 0x00, 0xdd, 0x00}
)

Functions

This section is empty.

Types

type Pack

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

func New added in v0.8.0

func New(file *os.File) (*Pack, error)

Creates an empty *Pack with the provided *os.File.

The underlying contents of the file are NOT cleared unless *Pack.Flush has been called BEFORE a call to *Pack.ReadRecords. The contents of the *os.File are initialized with a signature ONLY if the length of the file is shorter than the signature.

func Open

func Open(path string) (*Pack, error)

Creates a *Pack with the *os.File specified by path.

The existing contents of the *os.File are loaded into the *Pack. If there is an error when creating the *Pack of loading the *Pack's contents, the file is closed.

Calling *Pack.Close on a *Pack created through a call from Open causes the underlying file to be closed.

func (*Pack) Close

func (pack *Pack) Close() (err error)

Flushes the contents of the *Pack and then closes the underlying *os.File ONLY if the *Pack was created through a call to Open.

func (*Pack) Flush added in v0.8.0

func (pack *Pack) Flush() error

Writes the *Pack's records and tailer data to the end of the underlying *os.File.

If the written data is less than the total size of the *os.File the file is truncated to the number of written bytes.

func (*Pack) ReadRecords added in v0.8.0

func (pack *Pack) ReadRecords() ([]*Record, error)

Reads the record data from the underlying *os.File and returns the resulting slice. The *Pack's internal records are updated with this result.

func (*Pack) Records

func (pack *Pack) Records() []*Record

Returns the *Pack's records.

*Pack.Records never returns a nil slice.

func (*Pack) Revision added in v0.8.0

func (pack *Pack) Revision() uint32

func (*Pack) Search

func (pack *Pack) Search(path string) (*Record, bool)

func (*Pack) Store added in v0.8.0

func (pack *Pack) Store(path string, info archive.Info, compressed bool, r io.Reader) (err error)

Adds or updates a record within the *Pack.

One or more calls to *Pack.Store should be followed by a call to either *Pack.Flush or *Pack.Close to update the contents of the underlying *os.File.

func (*Pack) WriteTo added in v0.8.0

func (pack *Pack) WriteTo(w io.Writer) (n int64, err error)

type Record

type Record struct {
	Crc uint32
	binarytree.Indices

	archive.Info
	IsCompressed bool
	// contains filtered or unexported fields
}

func (*Record) DataPointer added in v0.8.0

func (record *Record) DataPointer() uint32

func (*Record) DataSize added in v0.8.0

func (record *Record) DataSize() uint32

func (*Record) Section

func (record *Record) Section() (io.Reader, hash.Hash, error)

Returns an io.Reader and md5 hash writer for the record's data. If the record is compressed, the underlying io.Reader is wrapped by a *segmented.DataReader.

The hash.Hash value contains the md5 chunksum for the uncompressed data, but only for the data read out of the io.Reader.

Example:

reader, hash, err := record.Section()

if err != nil {
    return err
}

// The contents of the reader must be read before calling hash.Sum(nil)
if err := io.Copy(file, reader); err != nil {
    return err
}

fmt.Println(hash.Sum(nil)) // the resulting checksum

func (*Record) TreeIndices added in v0.8.0

func (record *Record) TreeIndices() *binarytree.Indices

func (*Record) WriteTo added in v0.8.0

func (record *Record) WriteTo(w io.Writer) (n int64, err error)

type RecordError

type RecordError struct {
	Err   error
	Field string
}

func (*RecordError) Error

func (err *RecordError) Error() string

func (*RecordError) Is

func (err *RecordError) Is(target error) bool

func (*RecordError) Unwrap

func (err *RecordError) Unwrap() error

Jump to

Keyboard shortcuts

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