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 ¶
- Variables
- func IndexHeader(r io.Reader) (size int64, dir string, err error)
- func ListToChan(dir string) (entries chan interface{})
- func ListToFunc(dir string, entryFunc func(*ListEntry) error) error
- func PostfixFileSize(content []byte) int64
- func WriteIndex(dir string, w io.Writer) error
- type BinaryEntry
- type EntryType
- type IndexReader
- func (ir *IndexReader) SeekAndWrite(filename string, pos, maxbytes int64, informFunc ...func(maxBytes int64)) (int64, error)
- func (ir *IndexReader) SeekByte(pos int64) error
- func (ir *IndexReader) SeekFile(filename string, pos int64) error
- func (ir *IndexReader) Size() int64
- func (ir *IndexReader) WriteTar(maxbytes int64) (int64, error)
- type ListEntry
- type PathMod
- type PostfixFile
- type TarWriter
Constants ¶
This section is empty.
Variables ¶
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") )
var ( ErrIndexFSMismatch = errors.New("index does not match filesystem") ErrUnsupported = errors.New("unsupported filetype") ErrSkipBoundary = errors.New("skip beyond file boundary") )
var (
ErrMissingHeader = errors.New("missing header")
)
Functions ¶
func IndexHeader ¶
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 ¶
ListToFunc produces a flow of list entries that are given to entryFunc for processing.
func PostfixFileSize ¶
PostfixFileSize is the size of a file with the given content.
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 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.
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.
type PostfixFile ¶
PostfixFile is a file that may be generated at the end of the tar stream.