Documentation
¶
Index ¶
- Constants
- Variables
- func AppendTarRecoveryRecord(filename string, pct int) error
- func Compress(inputFilePath, outputFilePath string) error
- func DetectFormat(r io.ReaderAt) (uint16, error)
- func Extract(inputFilePath, outputFilePath string) error
- func ExtractShadowFileToWriter(ra io.ReaderAt, fileSize int64, method uint16, targetName string, ...) error
- func GetCacheIndexPath(archivePath string) (string, error)
- func GetStandardIndexPath(archivePath string) (string, error)
- func IndexArchive(archivePath, indexPath string) error
- func IndexArchiveWithBackend(archivePath, indexPath string, backend IndexBackend) error
- func LocateShadowStream(ra io.ReaderAt, fileSize int64, method uint16) (int64, int64, error)
- func NewGzipIndexTrackingReader(r io.Reader) (*gzipIndexTrackingReader, error)
- func NewParallelGzipIndexedReader(ra io.ReaderAt, indexData []byte, concurrency int) io.ReadCloser
- func NewReader(r io.Reader) *tar.Reader
- func NewWriter(w io.Writer) *tar.Writer
- func ParallelDecompressGzipIndexed(ra io.ReaderAt, indexData []byte, w io.Writer, concurrency int) error
- func RegisterCompressor(method uint16, comp Compressor)
- func RegisterDecompressor(method uint16, dcomp Decompressor)
- func WriteMagicFooter(w io.Writer, method uint16, shadowStart, shadowSize int64) error
- type AppendMode
- type Archiver
- type ArchiverOption
- func WithArchiverDeterministic(b bool) ArchiverOption
- func WithArchiverDeterministicTime(t time.Time) ArchiverOption
- func WithArchiverEmbeddedIndex(b bool) ArchiverOption
- func WithArchiverIndex(path string) ArchiverOption
- func WithArchiverLevel(level int) ArchiverOption
- func WithArchiverLock(b bool) ArchiverOption
- func WithArchiverMethod(method uint16) ArchiverOption
- func WithArchiverPassword(p string) ArchiverOption
- func WithArchiverPathMapping(m map[string]string) ArchiverOption
- func WithArchiverRecovery(pct int) ArchiverOption
- func WithArchiverSplitSize(size int64) ArchiverOption
- func WithArchiverXattrs(b bool) ArchiverOption
- type ArcidxIndex
- func (idx *ArcidxIndex) Close() error
- func (idx *ArcidxIndex) GetClosestBlockOffset(table string, targetDataOffset int64) (*BlockOffset, error)
- func (idx *ArcidxIndex) GetGzipIndex() ([]byte, error)
- func (idx *ArcidxIndex) InitMetadata() error
- func (idx *ArcidxIndex) Insert(nodes []FileNode) error
- func (idx *ArcidxIndex) InsertBlockOffsets(table string, offsets []BlockOffset) error
- func (idx *ArcidxIndex) List(p string) ([]FileNode, error)
- func (idx *ArcidxIndex) Lookup(p string) (*FileNode, error)
- func (idx *ArcidxIndex) RecursiveSize(p string) (int64, error)
- func (idx *ArcidxIndex) SaveGzipIndex(data []byte) error
- type BlockOffset
- type BlockOffsetExporter
- type BlockOffsetImporter
- type BzipReaderAt
- type Compressor
- type Decompressor
- type Extractor
- type ExtractorOption
- func WithExtractorChownErrorHandler(fn func(name string, err error) error) ExtractorOption
- func WithExtractorConcurrency(n int) ExtractorOption
- func WithExtractorIncremental(b bool) ExtractorOption
- func WithExtractorKeepBroken(b bool) ExtractorOption
- func WithExtractorKeepNewerFiles(keep bool) ExtractorOption
- func WithExtractorKeepOldFiles(keep bool) ExtractorOption
- func WithExtractorMaxFileSize(n int64) ExtractorOption
- func WithExtractorMaxRatio(n int64) ExtractorOption
- func WithExtractorNoTimes(noTimes bool) ExtractorOption
- func WithExtractorNumericOwner(b bool) ExtractorOption
- func WithExtractorPassword(p string) ExtractorOption
- func WithExtractorSafeWrites(b bool) ExtractorOption
- func WithExtractorSparse(b bool) ExtractorOption
- func WithExtractorStripComponents(count int) ExtractorOption
- func WithExtractorTolerant(b bool) ExtractorOption
- func WithExtractorUnlinkFirst(b bool) ExtractorOption
- func WithExtractorXattrs(b bool) ExtractorOption
- type FSOption
- type FileIndex
- type FileNode
- type Format
- type GzipIndexExporter
- type GzipIndexImporter
- type GzipReaderAt
- type Header
- type Index
- func (idx *Index) Close() error
- func (idx *Index) GetClosestBlockOffset(table string, targetDataOffset int64) (*BlockOffset, error)
- func (idx *Index) GetGzipIndex() ([]byte, error)
- func (idx *Index) InitMetadata() error
- func (idx *Index) Insert(nodes []FileNode) error
- func (idx *Index) InsertBlockOffsets(table string, offsets []BlockOffset) error
- func (idx *Index) List(p string) ([]FileNode, error)
- func (idx *Index) Lookup(p string) (*FileNode, error)
- func (idx *Index) RecursiveSize(p string) (int64, error)
- func (idx *Index) SaveGzipIndex(data []byte) error
- type IndexBackend
- type MultiVolumeReader
- type MultiVolumeWriter
- type ReadCloser
- type Reader
- type TarFS
- type Updater
- type WriteCloser
- type Writer
- type WriterOption
- type XCryptHeader
- type XzReaderAt
- type ZstdReaderAt
Constants ¶
const ( Store uint16 = 0 GZIP uint16 = 1 BZIP2 uint16 = 2 XZ uint16 = 3 ZSTD uint16 = 4 )
Compression formats
const ( TypeReg = tar.TypeReg TypeRegA = tar.TypeRegA TypeLink = tar.TypeLink TypeSymlink = tar.TypeSymlink TypeChar = tar.TypeChar TypeBlock = tar.TypeBlock TypeDir = tar.TypeDir TypeFifo = tar.TypeFifo TypeCont = tar.TypeCont TypeXHeader = tar.TypeXHeader TypeXGlobalHeader = tar.TypeXGlobalHeader TypeGNUSparse = tar.TypeGNUSparse TypeGNULongName = tar.TypeGNULongName TypeGNULongLink = tar.TypeGNULongLink TypeVol = 'V' // GNUTYPE_VOLHDR (Volume header) TypeGNUDumpDir = 'D' // GNUTYPE_DUMPDIR TypeGNUMultiVol = 'M' // GNUTYPE_MULTIVOL )
const ( FormatUnknown = tar.FormatUnknown FormatUSTAR = tar.FormatUSTAR FormatPAX = tar.FormatPAX FormatGNU = tar.FormatGNU )
const DefaultGzipCheckpointSpacing = 2 << 20
DefaultGzipCheckpointSpacing is the uncompressed distance between checkpoints: each one keeps a 32 KiB window, so this is about 1.6% memory overhead while a far read decodes at most this much beyond its target.
const MappedStringMark = '\uFFFE'
const MappedStringMarkStr = "\uFFFE"
Variables ¶
var ( ErrHeader = tar.ErrHeader ErrWriteTooLong = tar.ErrWriteTooLong ErrFieldTooLong = tar.ErrFieldTooLong ErrWriteAfterClose = tar.ErrWriteAfterClose )
var ErrAlgorithm = errors.New("tar: unsupported compression algorithm")
var ErrArchiveLocked = errors.New("tar: cannot modify archive, it is locked")
var ErrArcidxNotFound = errors.New("arcidx: not found")
ErrArcidxNotFound is returned by ArcidxIndex.Lookup and ArcidxIndex.GetClosestBlockOffset when there is no matching entry.
var ErrDataAfterEnd = errors.New("tar: data after the end of the archive; not updating it in place")
ErrDataAfterEnd is returned by NewUpdater for an uncompressed archive that has something other than zero blocks after its end-of-archive marker and before its embedded index, if it has one. An entry written there would not be seen, and truncating the archive to append would destroy what is there.
var ErrNoGzipIndex = errors.New("tar: no GZIDX checkpoints available for parallel decompression")
ErrNoGzipIndex is returned by the parallel GZIP decompression helpers when no usable GZIDX checkpoints are available.
Functions ¶
func AppendTarRecoveryRecord ¶ added in v0.1.33
AppendTarRecoveryRecord генерирует PAR2 для TAR-архива и дописывает его в хвост с F4-футером
func DetectFormat ¶
DetectFormat looks at the magic bytes to determine the compression method.
func ExtractShadowFileToWriter ¶ added in v0.1.101
func ExtractShadowFileToWriter(ra io.ReaderAt, fileSize int64, method uint16, targetName string, out io.Writer) error
ExtractShadowFileToWriter extracts a specific file payload from the Stream 2 metadata shadow stream.
func GetCacheIndexPath ¶ added in v0.1.119
GetCacheIndexPath returns the path to the cache directory for the SQLite index.
func GetStandardIndexPath ¶ added in v0.1.10
GetStandardIndexPath attempts to place the SQLite index next to the archive (sidecar). If the directory is read-only, it falls back to the user's cache directory.
func IndexArchive ¶
IndexArchive builds the index of an archive at indexPath, using whichever backend the tarindex_simple build tag currently binds to OpenIndex/Index (IndexBackendAuto). An index that could not be finished is removed again: the next open of the archive finds the file, takes it for a finished index and lists an empty archive without reporting anything (f4 issue #1187, where a tar.xz that cannot be decompressed at all opened as empty on the second try).
func IndexArchiveWithBackend ¶ added in v0.1.137
func IndexArchiveWithBackend(archivePath, indexPath string, backend IndexBackend) error
IndexArchiveWithBackend is IndexArchive with an explicit IndexBackend (index_backend.go), so a caller that asked NewFS/WithFSIndexBackend for a specific backend gets an index actually written in that backend's format, not the tag-bound default. fs.go's prepareIndex uses this instead of IndexArchive so building a fresh index and then opening it (the very next step in prepareIndex) agree on which backend they mean.
func LocateShadowStream ¶ added in v0.1.32
LocateShadowStream finds the F4SS Magic Footer and returns the physical offset and size of Stream 2.
func NewGzipIndexTrackingReader ¶ added in v0.1.100
func NewParallelGzipIndexedReader ¶ added in v0.1.138
NewParallelGzipIndexedReader streams the decompressed bytes of a GZIP archive using ParallelDecompressGzipIndexed under the hood, so callers that need an io.Reader (e.g. archive/tar.NewReader or this package's tar.NewReader) can benefit from parallel inflate without buffering the whole decompressed archive in memory up front: segments are still decoded concurrently ahead of the reader, but handed to the consumer as an ordinary streaming Read().
func ParallelDecompressGzipIndexed ¶ added in v0.1.138
func ParallelDecompressGzipIndexed(ra io.ReaderAt, indexData []byte, w io.Writer, concurrency int) error
ParallelDecompressGzipIndexed decompresses a whole GZIP stream described by a previously saved GZIDX index (see GzipIndexExporter.ExportGzipIndex / FileIndex.GetGzipIndex) by splitting the work across the saved checkpoints: each segment between two consecutive checkpoints is inflated by its own goroutine, independently seeded from that checkpoint's saved offset and (when present) 32KB sliding-dictionary window, so multiple CPU cores can decompress the same archive concurrently instead of the single sequential decompressor used by OpenReader/Extract. Segments are written to w strictly in ascending order, so the output is byte-for-byte identical to a plain sequential decompression of the same stream.
concurrency caps how many segments are inflated at once; concurrency <= 0 selects runtime.GOMAXPROCS(0).
func RegisterCompressor ¶
func RegisterCompressor(method uint16, comp Compressor)
func RegisterDecompressor ¶
func RegisterDecompressor(method uint16, dcomp Decompressor)
Types ¶
type Archiver ¶
type Archiver struct {
// contains filtered or unexported fields
}
func NewArchiver ¶
func NewArchiver(filename string, chroot string, opts ...ArchiverOption) (*Archiver, error)
func (*Archiver) Archive ¶
Archive writes files to the tar sequentially. For TAR, unlike ZIP, we cannot write data streams concurrently to the same file.
func (*Archiver) SetComment ¶ added in v0.1.40
SetComment sets the global archive comment stored inside the F4SS shadow metadata index.
type ArchiverOption ¶
type ArchiverOption func(*archiverOptions) error
func WithArchiverDeterministic ¶ added in v0.1.138
func WithArchiverDeterministic(b bool) ArchiverOption
WithArchiverDeterministic enables "torrenttar"-style deterministic output, analogous to the torrentzip convention for ZIP: combined with the alphabetical entry order Archive already produces, it normalizes every entry's mtime/atime/ctime, uid/gid, resolved owner/group names and platform-specific extended metadata (POSIX ACLs, SELinux labels, other xattrs, Windows security descriptors), none of which are part of the archived content itself but which otherwise make the .tar depend on when, where and as whom it was built. With this enabled, archiving the same file tree twice always produces a byte-identical archive. The fixed modification time defaults to the Unix epoch; use WithArchiverDeterministicTime to pick a different one (e.g. a build's SOURCE_DATE_EPOCH).
func WithArchiverDeterministicTime ¶ added in v0.1.138
func WithArchiverDeterministicTime(t time.Time) ArchiverOption
WithArchiverDeterministicTime is like WithArchiverDeterministic(true) but pins the fixed modification time recorded for every entry to t instead of the Unix epoch.
func WithArchiverEmbeddedIndex ¶ added in v0.1.28
func WithArchiverEmbeddedIndex(b bool) ArchiverOption
func WithArchiverIndex ¶ added in v0.1.8
func WithArchiverIndex(path string) ArchiverOption
func WithArchiverLevel ¶ added in v0.1.47
func WithArchiverLevel(level int) ArchiverOption
WithArchiverLevel sets the compression level.
func WithArchiverLock ¶ added in v0.1.40
func WithArchiverLock(b bool) ArchiverOption
WithArchiverLock locks the archive to prevent modifications.
func WithArchiverMethod ¶
func WithArchiverMethod(method uint16) ArchiverOption
func WithArchiverPassword ¶ added in v0.1.32
func WithArchiverPassword(p string) ArchiverOption
WithArchiverEmbeddedIndex appends the index directly inside the archive (F4 Shadow Stream). WithArchiverPassword enables F4Crypt AES-256-CTR encryption for the archive.
func WithArchiverPathMapping ¶ added in v0.1.57
func WithArchiverPathMapping(m map[string]string) ArchiverOption
WithArchiverPathMapping sets the path mapping for logical names in the archive.
func WithArchiverRecovery ¶ added in v0.1.34
func WithArchiverRecovery(pct int) ArchiverOption
WithArchiverRecovery устанавливает процент избыточности PAR2 для защиты архива
func WithArchiverSplitSize ¶ added in v0.1.37
func WithArchiverSplitSize(size int64) ArchiverOption
WithArchiverSplitSize enables creation of multi-volume archives
func WithArchiverXattrs ¶ added in v0.1.13
func WithArchiverXattrs(b bool) ArchiverOption
WithArchiverXattrs enables archiving of extended attributes (xattrs, POSIX ACLs, SELinux).
type ArcidxIndex ¶ added in v0.1.137
type ArcidxIndex struct {
// contains filtered or unexported fields
}
ArcidxIndex is the FlatBuffers-backed counterpart of the sqlite Index type. It implements the same set of methods (Close, InitMetadata, Insert, Lookup, List, RecursiveSize, InsertBlockOffsets, GetClosestBlockOffset, GetGzipIndex, SaveGzipIndex) with the same signatures, using the shared FileNode/BlockOffset domain types from sqlite.go, so calling code can choose either backend without depending on sqlite-specific types.
func NewArcidxIndex ¶ added in v0.1.137
func NewArcidxIndex(path string) (*ArcidxIndex, error)
NewArcidxIndex creates a brand-new, empty, in-memory index that will be serialized to path on Close. Any existing file at path is left untouched until Close overwrites it; callers that want a guaranteed-fresh file (like indexer_enabled.go does for sqlite) should remove the old file themselves first.
func OpenArcidxIndex ¶ added in v0.1.137
func OpenArcidxIndex(path string) (*ArcidxIndex, error)
OpenArcidxIndex opens path for reading (and, once a write method is called, for read-modify-write access). If path does not exist or is empty, it behaves like NewArcidxIndex: this mirrors OpenIndex's "CREATE TABLE IF NOT EXISTS" semantics for a brand-new sqlite file. If path exists but its contents cannot be parsed as a valid ArchiveIndex FlatBuffers message, an error is returned instead of silently starting from empty, so callers can tell "no index yet" apart from "corrupted index".
func (*ArcidxIndex) Close ¶ added in v0.1.137
func (idx *ArcidxIndex) Close() error
Close flushes any buffered writes to disk (as a single FlatBuffers ArchiveIndex message, written atomically) and marks the index unusable. Calling Close on an index that was only ever read from (never materialized) is a cheap no-op, matching sql.DB.Close's idempotency.
func (*ArcidxIndex) GetClosestBlockOffset ¶ added in v0.1.137
func (idx *ArcidxIndex) GetClosestBlockOffset(table string, targetDataOffset int64) (*BlockOffset, error)
GetClosestBlockOffset returns the entry with the largest DataOffset that is still <= targetDataOffset, binary-searching the compression_blob.
func (*ArcidxIndex) GetGzipIndex ¶ added in v0.1.137
func (idx *ArcidxIndex) GetGzipIndex() ([]byte, error)
GetGzipIndex returns the raw serialized gzip random-access index previously stored with SaveGzipIndex, or (nil, nil) if none was saved.
func (*ArcidxIndex) InitMetadata ¶ added in v0.1.137
func (idx *ArcidxIndex) InitMetadata() error
InitMetadata records the backend identity in the index. Unlike sqlite's InitMetadata, which inserts free-form (name, version) rows into a "versions" table, this only has room for ArchiveIndex.backend_name / .version, which is what it sets.
func (*ArcidxIndex) Insert ¶ added in v0.1.137
func (idx *ArcidxIndex) Insert(nodes []FileNode) error
Insert adds nodes to the index, deduplicating paths, xattr keys and metadata tuples, and skipping any (path, name, offsetheader) triple already present (mirroring sqlite_enabled.go's `ON CONFLICT DO NOTHING`).
func (*ArcidxIndex) InsertBlockOffsets ¶ added in v0.1.137
func (idx *ArcidxIndex) InsertBlockOffsets(table string, offsets []BlockOffset) error
InsertBlockOffsets stores the (blockoffset, dataoffset) pairs used for random access into block-based compression formats (ZSTD, BZIP2). Unlike sqlite's per-key INSERT OR REPLACE table, this schema only has one compression_format/compression_blob pair for the whole index, so this is a wholesale replace, not an incremental merge; see the package doc comment.
func (*ArcidxIndex) List ¶ added in v0.1.137
func (idx *ArcidxIndex) List(p string) ([]FileNode, error)
List returns the latest entry for every distinct name directly under p (a ReadDir-style listing).
func (*ArcidxIndex) Lookup ¶ added in v0.1.137
func (idx *ArcidxIndex) Lookup(p string) (*FileNode, error)
Lookup returns the latest (highest offset_header) entry for path p.
func (*ArcidxIndex) RecursiveSize ¶ added in v0.1.137
func (idx *ArcidxIndex) RecursiveSize(p string) (int64, error)
RecursiveSize sums the size of the latest version of every file at or below p (p itself included), matching sqlite_enabled.go's semantics.
func (*ArcidxIndex) SaveGzipIndex ¶ added in v0.1.137
func (idx *ArcidxIndex) SaveGzipIndex(data []byte) error
SaveGzipIndex stores data (as produced by GzipIndexExporter) as the index's compression blob.
type BlockOffset ¶ added in v0.1.1
type BlockOffsetExporter ¶ added in v0.1.1
type BlockOffsetExporter interface {
ExportBlockOffsets() []BlockOffset
}
BlockOffsetExporter exports boundary maps for block-based compression formats (ZSTD, BZIP2).
type BlockOffsetImporter ¶ added in v0.1.1
type BlockOffsetImporter interface {
ResumeFromBlockOffset(r io.ReaderAt, bo *BlockOffset) (io.ReadCloser, error)
}
BlockOffsetImporter resumes decompression from a specific block boundary.
type BzipReaderAt ¶ added in v0.1.141
type BzipReaderAt struct {
// contains filtered or unexported fields
}
BzipReaderAt gives random access to the uncompressed bytes of a bzip2 file available only as an io.ReaderAt. A bzip2 stream is a sequence of blocks that are compressed independently, each starting with the 48-bit magic 0x314159265359 at any bit position, so the file is scanned once for those magics and a read decodes only the block or blocks it falls in. A block is decoded on its own by giving the decoder a one-block stream made of its bits (the block's own CRC doubles as the stream CRC of a single block). Sizes of the blocks are learned by decoding them, so the first read at a far offset decodes the blocks before it once; after that the sizes are known. Several concatenated streams are supported (unxed/f4#1678). Safe for concurrent use; calls are serialised.
func NewBzipReaderAt ¶ added in v0.1.141
func NewBzipReaderAt(ra io.ReaderAt, size int64) (*BzipReaderAt, error)
NewBzipReaderAt opens ra, size bytes of bzip2 data.
func (*BzipReaderAt) Close ¶ added in v0.1.141
func (z *BzipReaderAt) Close() error
Close drops the cached block. The ReaderAt is the caller's.
func (*BzipReaderAt) Decoded ¶ added in v0.1.141
func (z *BzipReaderAt) Decoded() int64
Decoded reports how many uncompressed bytes have been decoded in total.
func (*BzipReaderAt) ReadAt ¶ added in v0.1.141
func (z *BzipReaderAt) ReadAt(p []byte, off int64) (int, error)
ReadAt implements io.ReaderAt over the uncompressed data.
func (*BzipReaderAt) Size ¶ added in v0.1.141
func (z *BzipReaderAt) Size() int64
Size returns the uncompressed size once every block has been sized, else -1.
type Compressor ¶
type Compressor func(w io.Writer) (io.WriteCloser, error)
type Decompressor ¶
type Decompressor interface {
Decompress(r io.Reader) (io.ReadCloser, error)
}
type Extractor ¶
type Extractor struct {
// contains filtered or unexported fields
}
func NewExtractor ¶
func NewExtractor(filename, chroot string, opts ...ExtractorOption) (*Extractor, error)
type ExtractorOption ¶
type ExtractorOption func(*extractorOptions) error
func WithExtractorChownErrorHandler ¶
func WithExtractorChownErrorHandler(fn func(name string, err error) error) ExtractorOption
WithExtractorChownErrorHandler allows gracefully ignoring chown errors which frequently happen when extracting archives as an unprivileged user.
func WithExtractorConcurrency ¶
func WithExtractorConcurrency(n int) ExtractorOption
func WithExtractorIncremental ¶ added in v0.1.13
func WithExtractorIncremental(b bool) ExtractorOption
WithExtractorIncremental enables processing of GNU Dumpdir headers to remove deleted files during incremental restores.
func WithExtractorKeepBroken ¶ added in v0.1.22
func WithExtractorKeepBroken(b bool) ExtractorOption
func WithExtractorKeepNewerFiles ¶ added in v0.1.13
func WithExtractorKeepNewerFiles(keep bool) ExtractorOption
WithExtractorKeepNewerFiles prevents overwriting files that are newer on disk (--keep-newer-files)
func WithExtractorKeepOldFiles ¶ added in v0.1.13
func WithExtractorKeepOldFiles(keep bool) ExtractorOption
WithExtractorKeepOldFiles prevents overwriting existing files (-k or --keep-old-files)
func WithExtractorMaxFileSize ¶
func WithExtractorMaxFileSize(n int64) ExtractorOption
func WithExtractorMaxRatio ¶
func WithExtractorMaxRatio(n int64) ExtractorOption
func WithExtractorNoTimes ¶ added in v0.1.13
func WithExtractorNoTimes(noTimes bool) ExtractorOption
WithExtractorNoTimes prevents restoring original modification times (-m / --touch)
func WithExtractorNumericOwner ¶ added in v0.1.13
func WithExtractorNumericOwner(b bool) ExtractorOption
WithExtractorNumericOwner always uses numeric user/group IDs from the archive rather than resolving Uname/Gname (--numeric-owner).
func WithExtractorPassword ¶ added in v0.1.32
func WithExtractorPassword(p string) ExtractorOption
WithExtractorSafeWrites extracts files atomically by writing to a temporary file and renaming (--safe-writes). WithExtractorPassword provides the password for decrypting F4Crypt encrypted archives.
func WithExtractorSafeWrites ¶ added in v0.1.13
func WithExtractorSafeWrites(b bool) ExtractorOption
func WithExtractorSparse ¶ added in v0.1.13
func WithExtractorSparse(b bool) ExtractorOption
WithExtractorSparse enables extracting files as sparse files by seeking over zero-blocks (-S, --sparse).
func WithExtractorStripComponents ¶ added in v0.1.13
func WithExtractorStripComponents(count int) ExtractorOption
WithExtractorStripComponents strips the specified number of leading components from file names on extraction (--strip-components)
func WithExtractorTolerant ¶ added in v0.1.25
func WithExtractorTolerant(b bool) ExtractorOption
func WithExtractorUnlinkFirst ¶ added in v0.1.13
func WithExtractorUnlinkFirst(b bool) ExtractorOption
WithExtractorUnlinkFirst removes existing files prior to extracting over them (-U, --unlink-first).
func WithExtractorXattrs ¶ added in v0.1.13
func WithExtractorXattrs(b bool) ExtractorOption
WithExtractorXattrs enables restoration of extended attributes (xattrs, POSIX ACLs, SELinux).
type FSOption ¶ added in v0.1.32
type FSOption func(*fsOptions)
func WithFSIndexBackend ¶ added in v0.1.137
func WithFSIndexBackend(b IndexBackend) FSOption
WithFSIndexBackend explicitly selects which FileIndex implementation NewFS opens (see IndexBackend in index_backend.go). Omitting this option keeps the pre-existing IndexBackendAuto behavior: whichever backend the tarindex_simple build tag currently binds to OpenIndex/Index.
func WithFSPassword ¶ added in v0.1.32
WithFSPassword provides the password for decrypting F4Crypt encrypted archives in TarFS.
type FileIndex ¶ added in v0.1.137
type FileIndex interface {
Close() error
InitMetadata() error
Insert(nodes []FileNode) error
Lookup(p string) (*FileNode, error)
List(p string) ([]FileNode, error)
RecursiveSize(p string) (int64, error)
InsertBlockOffsets(table string, offsets []BlockOffset) error
GetClosestBlockOffset(table string, targetDataOffset int64) (*BlockOffset, error)
GetGzipIndex() ([]byte, error)
SaveGzipIndex(data []byte) error
}
FileIndex is the method set both index backends implement: the SQLite-backed Index (sqlite_enabled.go/sqlite_disabled.go) and the FlatBuffers-backed ArcidxIndex (arcidx_index.go, unxed/tar#9). TarFS.Index (fs.go) is declared as this interface, not as a concrete *Index, so a single TarFS value can hold either backend - chosen explicitly via WithFSIndexBackend, or left to the tarindex_simple build tag as before - without needing two different builds of the tar package at once.
Every other caller of OpenIndex (writer.go, indexer_enabled.go) is untouched: they keep using the tag-bound Index/OpenIndex names directly, exactly as before this file was added.
type GzipIndexExporter ¶ added in v0.1.1
GzipIndexExporter exports the complete serialized GZIP index (compatible with zran.c/rapidgzip).
type GzipIndexImporter ¶ added in v0.1.1
type GzipIndexImporter interface {
ResumeFromGzipIndex(r io.ReaderAt, indexData []byte, targetOffset int64) (reader io.ReadCloser, uncompOffset int64, err error)
}
GzipIndexImporter resumes GZIP decompression using the serialized index.
type GzipReaderAt ¶ added in v0.1.138
type GzipReaderAt struct {
// contains filtered or unexported fields
}
GzipReaderAt gives random access to the uncompressed bytes of a GZIP file that is only available as an io.ReaderAt (a member of another archive, a remote file), without an index saved beforehand and without a local path.
It builds the checkpoint index (GZIDX: a position in the deflate stream plus the 32 KiB window, every spacing bytes) as it goes. A read past everything scanned so far continues the one sequential scan, and serves its bytes straight from it; a read behind the scan resumes from the nearest earlier checkpoint. So the first pass over the file costs one decompression, and a later read anywhere costs at most one checkpoint interval, never a decompression from the start (f4#1678).
Multi-member (concatenated) files are supported. Safe for concurrent use; calls are serialised.
func NewGzipReaderAt ¶ added in v0.1.138
NewGzipReaderAt opens ra, size bytes of GZIP data, for random access. spacing <= 0 selects DefaultGzipCheckpointSpacing.
func (*GzipReaderAt) Close ¶ added in v0.1.138
func (g *GzipReaderAt) Close() error
Close releases the scan. The underlying ReaderAt is the caller's.
func (*GzipReaderAt) Decoded ¶ added in v0.1.138
func (g *GzipReaderAt) Decoded() int64
Decoded reports how many uncompressed bytes have been decoded in total.
func (*GzipReaderAt) ReadAt ¶ added in v0.1.138
func (g *GzipReaderAt) ReadAt(p []byte, off int64) (int, error)
ReadAt implements io.ReaderAt over the uncompressed data.
func (*GzipReaderAt) Size ¶ added in v0.1.138
func (g *GzipReaderAt) Size() int64
Size returns the uncompressed size once a read has reached the end of the data, and -1 before that.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func (*Index) GetClosestBlockOffset ¶ added in v0.1.1
func (idx *Index) GetClosestBlockOffset(table string, targetDataOffset int64) (*BlockOffset, error)
func (*Index) GetGzipIndex ¶ added in v0.1.1
func (*Index) InitMetadata ¶ added in v0.1.29
func (*Index) InsertBlockOffsets ¶ added in v0.1.1
func (idx *Index) InsertBlockOffsets(table string, offsets []BlockOffset) error
func (*Index) SaveGzipIndex ¶ added in v0.1.1
type IndexBackend ¶ added in v0.1.137
type IndexBackend int
IndexBackend explicitly selects which FileIndex implementation NewFS opens for a given TarFS, independent of the tarindex_simple build tag. Pass one via WithFSIndexBackend.
const ( // IndexBackendAuto (the default) keeps the pre-existing, tag-bound // behavior: NewFS opens whatever OpenIndex/Index currently name for this // build - the SQLite backend, unless the binary was built with // -tags tarindex_simple, in which case ArcidxIndex. IndexBackendAuto IndexBackend = iota // IndexBackendSQLite always opens the SQLite-backed Index, regardless of // the tarindex_simple tag. Only functional in builds that actually // compiled the SQLite backend in: on a tarindex_simple build it returns // ErrSQLiteBackendUnavailable (see tarindex_simple.go), and on the BSD/ // Solaris/illumos OSes without cgo-free SQLite it returns the same // errNoSqlite the tag-bound OpenIndex already returns there // (sqlite_disabled.go) - not a new limitation, just reachable // explicitly now. IndexBackendSQLite // IndexBackendArcidx always opens the FlatBuffers-backed ArcidxIndex. // arcidx_index.go has no build tag of its own, so this works in every // build, including ones that also have the SQLite backend compiled in. IndexBackendArcidx )
type MultiVolumeReader ¶ added in v0.1.37
type MultiVolumeReader struct {
// contains filtered or unexported fields
}
func OpenMultiVolume ¶ added in v0.1.37
func OpenMultiVolume(mainPath string, flag int) (*MultiVolumeReader, int64, error)
func (*MultiVolumeReader) Append ¶ added in v0.1.37
func (m *MultiVolumeReader) Append(data []byte) error
func (*MultiVolumeReader) Close ¶ added in v0.1.37
func (m *MultiVolumeReader) Close() error
type MultiVolumeWriter ¶ added in v0.1.37
type MultiVolumeWriter struct {
// contains filtered or unexported fields
}
func NewMultiVolumeWriter ¶ added in v0.1.37
func NewMultiVolumeWriter(mainPath string, splitSize int64) (*MultiVolumeWriter, error)
func (*MultiVolumeWriter) Close ¶ added in v0.1.37
func (m *MultiVolumeWriter) Close() error
func (*MultiVolumeWriter) Name ¶ added in v0.1.37
func (m *MultiVolumeWriter) Name() string
func (*MultiVolumeWriter) Sync ¶ added in v0.1.37
func (m *MultiVolumeWriter) Sync() error
type ReadCloser ¶
func OpenReader ¶
func OpenReader(name string) (*ReadCloser, error)
OpenReader opens a TAR or compressed TAR file (.tar, .tar.gz, .tar.zst, etc.).
func (*ReadCloser) Close ¶
func (rc *ReadCloser) Close() error
func (*ReadCloser) Next ¶ added in v0.1.42
func (rc *ReadCloser) Next() (*Header, error)
type TarFS ¶
type TarFS struct {
ArchivePath string
IndexPath string
Index FileIndex
// contains filtered or unexported fields
}
func NewFS ¶
NewFS opens a tar archive as a standard Go fs.FS (File System). This enables integration with http.FileServer, fs.WalkDir, etc. If the SQLite index does not exist, it will be generated automatically.
func (*TarFS) GetComment ¶ added in v0.1.40
GetComment retrieves the global archive comment stored in the F4SS shadow metadata index.
func (*TarFS) OpenParallelGzip ¶ added in v0.1.138
func (t *TarFS) OpenParallelGzip(concurrency int) (io.ReadCloser, error)
OpenParallelGzip opens the underlying archive of a GZIP-compressed TarFS for sequential reading (e.g. with this package's NewReader, to walk every entry, or with archive/tar), but decompresses it with ParallelDecompressGzipIndexed: independent goroutines inflate the archive's saved GZIDX checkpoints concurrently instead of the one sequential decompressor OpenReader/Extract normally use. It requires the FS to have been opened against a GZIP archive with a saved GZIDX index (see GetGzipIndex); ErrNoGzipIndex is returned when none is available.
concurrency caps how many segments are inflated at once; concurrency <= 0 selects runtime.GOMAXPROCS(0).
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater adds entries to an existing archive.
Every reader that follows the tar format stops at the end-of-archive blocks, so an appended entry has to take their place. An uncompressed archive is updated in place: it is cut back to where its last entry ends -- which also drops an embedded index (F4SS), since the index no longer describes the archive -- and entries are written from there. Appending the name of an entry the archive already holds removes that entry first.
A compressed archive cannot be cut there: its end-of-archive blocks are inside the compressed stream. Entries written after that stream were read by this package's reader, which carries on past end-of-archive, but not by tar or 7-Zip, which stop where the format says to. So appended entries are kept aside, and Close writes the archive anew: its entries, less those whose names were appended, then the appended ones, in one compressed stream. The embedded index is dropped here too.
func NewUpdater ¶
func NewUpdater(f *os.File, mode AppendMode, opts ...WriterOption) (*Updater, error)
func (*Updater) AppendHeader ¶ added in v0.1.129
AppendHeader adds an entry described by hdr -- a file, a directory, a link, a device node or a FIFO -- with the hdr.Size bytes r holds for a file, and nothing read from r for the other types.
func (*Updater) AppendReader ¶ added in v0.1.63
AppendReader creates a new file entry in the archive from an io.Reader stream.
type WriteCloser ¶
func CreateWriter ¶
func CreateWriter(name string, method uint16, opts ...WriterOption) (*WriteCloser, error)
func (*WriteCloser) Close ¶
func (wc *WriteCloser) Close() error
func (*WriteCloser) SetCompressionLevel ¶ added in v0.1.103
func (wc *WriteCloser) SetCompressionLevel(level int) error
func (*WriteCloser) WriteHeader ¶ added in v0.1.8
func (wc *WriteCloser) WriteHeader(hdr *Header) error
type WriterOption ¶ added in v0.1.8
type WriterOption func(*writerOptions)
func WithWriterIndex ¶ added in v0.1.8
func WithWriterIndex(indexPath string) WriterOption
WithWriterIndex enables on-the-fly indexing during archive creation.
func WithWriterLevel ¶ added in v0.1.47
func WithWriterLevel(level int) WriterOption
func WithWriterSplitSize ¶ added in v0.1.37
func WithWriterSplitSize(size int64) WriterOption
type XCryptHeader ¶ added in v0.1.49
type XCryptHeader struct {
Version uint8
KdfAlgo uint8
Cipher uint8
Iterations uint32
Salt []byte
IV []byte
MAC []byte
}
XCryptHeader represents the 93-byte binary header for encrypted streams
func (*XCryptHeader) DeriveKey ¶ added in v0.1.49
func (h *XCryptHeader) DeriveKey(password string) []byte
func (*XCryptHeader) Encode ¶ added in v0.1.49
func (h *XCryptHeader) Encode() []byte
type XzReaderAt ¶ added in v0.1.140
type XzReaderAt struct {
// contains filtered or unexported fields
}
XzReaderAt gives random access to the uncompressed bytes of an .xz file available only as an io.ReaderAt. The file's own index, which lists every block with its compressed and uncompressed size, is read from the end, so the exact uncompressed size is known at once and a read decodes only the block or blocks it falls in. A file written as one block (the default for a single thread) can only be decoded from its start; there a forward read continues the decoder it has and only a read going back starts over (unxed/f4#1678). Safe for concurrent use; calls are serialised.
func NewXzReaderAt ¶ added in v0.1.140
func NewXzReaderAt(ra io.ReaderAt, size int64) (*XzReaderAt, error)
NewXzReaderAt opens ra, size bytes of xz data.
func (*XzReaderAt) Close ¶ added in v0.1.140
func (x *XzReaderAt) Close() error
Close releases the decoder. The ReaderAt is the caller's.
func (*XzReaderAt) Decoded ¶ added in v0.1.140
func (x *XzReaderAt) Decoded() int64
Decoded reports how many uncompressed bytes have been decoded in total.
func (*XzReaderAt) ReadAt ¶ added in v0.1.140
func (x *XzReaderAt) ReadAt(p []byte, off int64) (int, error)
ReadAt implements io.ReaderAt over the uncompressed data.
func (*XzReaderAt) Size ¶ added in v0.1.140
func (x *XzReaderAt) Size() int64
Size returns the uncompressed size, known from the file's index.
type ZstdReaderAt ¶ added in v0.1.139
type ZstdReaderAt struct {
// contains filtered or unexported fields
}
ZstdReaderAt gives random access to the uncompressed bytes of a zstd file available only as an io.ReaderAt, using the frame boundaries. A zstd file made of several frames (pzstd, a chunked writer, zstd --seekable's data part, f4's own block-per-frame archives) can be entered at any frame: the frames are found by walking their block headers, without decompressing them, and a read decodes only the frame or frames it falls in.
A file that is one frame can only be decoded from its start, since a zstd block depends on the window before it; there a read continues the decoder it already has when it goes forward and starts again only when it goes back. Skippable frames are stepped over. Safe for concurrent use; calls are serialised (unxed/f4#1678).
func NewZstdReaderAt ¶ added in v0.1.139
func NewZstdReaderAt(ra io.ReaderAt, size int64) (*ZstdReaderAt, error)
NewZstdReaderAt opens ra, size bytes of zstd data.
func (*ZstdReaderAt) Close ¶ added in v0.1.139
func (z *ZstdReaderAt) Close() error
Close releases the decoder. The ReaderAt is the caller's.
func (*ZstdReaderAt) Decoded ¶ added in v0.1.139
func (z *ZstdReaderAt) Decoded() int64
Decoded reports how many uncompressed bytes have been decoded in total.
func (*ZstdReaderAt) ReadAt ¶ added in v0.1.139
func (z *ZstdReaderAt) ReadAt(p []byte, off int64) (int, error)
ReadAt implements io.ReaderAt over the uncompressed data.
func (*ZstdReaderAt) Size ¶ added in v0.1.139
func (z *ZstdReaderAt) Size() int64
Size returns the uncompressed size once every frame is known, else -1.
Source Files
¶
- archiver.go
- arcidx_index.go
- bzip_readerat.go
- compress.go
- crypto.go
- deterministic.go
- extractor.go
- fs.go
- fs_linux.go
- gzip_parallel.go
- gzip_readerat.go
- index_backend.go
- indexer.go
- indexer_enabled.go
- motw.go
- multivolume.go
- os_wrapper.go
- reader.go
- recovery.go
- shadow.go
- sqlite.go
- sqlite_enabled.go
- sys_linux.go
- sys_unix.go
- tar.go
- updater.go
- writer.go
- xz_readerat.go
- zstd_readerat.go