tarindex

package
v0.0.0-...-c2fc523 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: CC0-1.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tarindex lists the content of a directory and its subdirectories, including only directories, links and files. It produces a stream of paths and file sizes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSeek is returned if multiple seeks in the index are attempted.
	ErrNoSeek = errors.New("no more seeks")
	// ErrMissingFile is returned when a reference file does not exist in the index.
	ErrMissingFile = errors.New("reference file not found")
)
View Source
var (
	ErrIndexFSMismatch = errors.New("index does not match filesystem")
	ErrUnsupported     = errors.New("unsupported filetype")
	ErrSkipBoundary    = errors.New("skip beyond file boundary")
)
View Source
var (
	ErrMissingHeader = errors.New("missing header")
)

Functions

func IndexHeader

func IndexHeader(r io.Reader) (size int64, dir string, err error)

IndexHeader reads the header of the index file and returns the total size (without postfix files),and the root directory. In case of ErrMissingHeader only the root directory is usable. The filesize is indeterminate.

func ListToChan

func ListToChan(dir string) (entries chan interface{})

ListToChan produces a flow of list entries send to chan entries. The channel is closed after listing has been completed. The channel will contain either *ListEntry or error entries.

func ListToFunc

func ListToFunc(dir string, entryFunc func(*ListEntry) error) error

ListToFunc produces a flow of list entries that are given to entryFunc for processing.

func PostfixFileSize

func PostfixFileSize(content []byte) int64

PostfixFileSize is the size of a file with the given content.

func WriteIndex

func WriteIndex(dir string, w io.Writer) error

WriteIndex writes an index file. w should be an io.WriteSeeker if possible.

Types

type BinaryEntry

type BinaryEntry [binaryEntrySize]byte

BinaryEntry contains the size or offset, type and path of an entry.

func (BinaryEntry) ToListEntry

func (bin BinaryEntry) ToListEntry(offset int64) *ListEntry

ToListEntry returns a list entry from a BinaryEntry.

type EntryType

type EntryType byte
const (
	EntryTypeHeader    EntryType = 0xff
	EntryTypeDirectory EntryType = 0x01
	EntryTypeFile      EntryType = 0x02
	EntryTypeLink      EntryType = 0x03
)

type IndexReader

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

IndexReader parses a tar index and produces a (partial) tar stream.

func NewIndexReader

func NewIndexReader(r io.Reader, w io.Writer, postFixFile *PostfixFile) (*IndexReader, error)

NewIndexReader creates an IndexReader that reads the index from r and writes the tar stream to w. It may attach a postFixFile.

func (*IndexReader) SeekAndWrite

func (ir *IndexReader) SeekAndWrite(filename string, pos, maxbytes int64, informFunc ...func(maxBytes int64)) (int64, error)

SeekAndWrite generates a tar stream starting at either: - pos bytes from beginning of index if filename is empty. - pos bytes from the beginning of the file with name filename. If pos == 0 the complete tar stream is written. maxbytes limits how many bytes starting from the beginning of the archive should be written.

func (*IndexReader) SeekByte

func (ir *IndexReader) SeekByte(pos int64) error

SeekByte seeks through index to find the matching entry from which to produce the tar stream.

func (*IndexReader) SeekFile

func (ir *IndexReader) SeekFile(filename string, pos int64) error

SeekFile seeks through index to find the matching entry for filename, and then seeks pos bytes from there.

func (*IndexReader) Size

func (ir *IndexReader) Size() int64

Size returns the total size of the tar stream, if known, otherwise 0.

func (*IndexReader) WriteTar

func (ir *IndexReader) WriteTar(maxbytes int64) (int64, error)

WriteTar writes a (partial) tar stream from the current seek position.

type ListEntry

type ListEntry struct {
	Size      int64     // Size of the entry.
	Name      string    // Path of filesystem object.
	Type      EntryType // Directory, link, or regular file.
	FirstByte int64     // First byte occupied in the tar file. Only populated when reading.
	LastByte  int64     // Last byte occupied in the tar file. Only populated when reading.
}

ListEntry describes an entry in a list of tar file entries.

func (*ListEntry) BinaryEntry

func (entry *ListEntry) BinaryEntry(offset int64) (newOffset int64, binEntry *BinaryEntry)

BinaryEntry returns the binary entry for the ListEntry. If offset is given, it will be added to the size. This allows quick calculation about the last byte in a tar file occupied by the given entry.

func (*ListEntry) TarSize

func (entry *ListEntry) TarSize() int64

type PathMod

type PathMod struct {
	BaseDir string
	ModDir  string
}

func (PathMod) FixPath

func (mod PathMod) FixPath(orig string) string

type PostfixFile

type PostfixFile struct {
	Name    string
	Content []byte
}

PostfixFile is a file that may be generated at the end of the tar stream.

type TarWriter

type TarWriter struct {
	FixPath func(string) string
	// contains filtered or unexported fields
}

func NewTarWriter

func NewTarWriter(w io.Writer) *TarWriter

func (*TarWriter) AddPostfixFile

func (tw *TarWriter) AddPostfixFile(name string, content []byte, skipbytes, maxbytes int64) (int64, error)

AddPostfixFile adds a file with name and content to the archive.

func (*TarWriter) Close

func (tw *TarWriter) Close(skipbytes, maxbytes int64) (int64, error)

Close the archive.

func (*TarWriter) WriteEntry

func (tw *TarWriter) WriteEntry(e *ListEntry, skipbytes, maxbytes int64) (int64, error)

WriteEntry writes e's tar entry (header and content) to w. It skips the first skipbytes bytes.

Jump to

Keyboard shortcuts

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