tar

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeReg           = tar.TypeReg
	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
)

Variables

This section is empty.

Functions

func NewFs

func NewFs(w *tar.Writer) afero.Fs

NewFs returns an afero.Fs implementation that writes its contents to the provided tar.Writer. The returned filesystem is write-only and exposes a subset of operations that add files and directories to the underlying tar stream.

The caller retains ownership of the tar.Writer: NewFs does not close or flush the writer, and it does not perform any synchronization. The caller is responsible for calling Close on the tar.Writer when all filesystem operations are complete.

Example:

tw := tar.NewWriter(dst)
defer tw.Close()

fs := NewFs(tw)
// Use any afero helpers with fs, for example:
//   afero.WriteFile(fs, "path/to/file.txt", []byte("data"), 0o644)

func NewReader

func NewReader(r io.Reader) *tar.Reader

NewReader returns a new tar.Reader that reads a tar archive from r.

This function is a thin wrapper around archive/tar.NewReader and is provided to mirror NewWriter and keep tar I/O behind this package's API. Using this constructor instead of archive/tar.NewReader directly helps keep callers decoupled from the underlying tar implementation.

func NewWriter

func NewWriter(w io.Writer) *tar.Writer

NewWriter returns a new tar.Writer that writes a tar archive to w.

This function is a thin wrapper around archive/tar.NewWriter and exists to provide a stable, package-local API for tar output. Callers should prefer using this constructor instead of archive/tar.NewWriter directly so that tar handling can be centralized in this package and extended in the future without requiring changes at call sites.

Types

type File

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

func (*File) Close

func (f *File) Close() error

Close implements afero.File.

func (*File) Name

func (f *File) Name() string

Name implements afero.File.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Read implements afero.File.

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements afero.File.

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir implements afero.File.

func (*File) Readdirnames

func (f *File) Readdirnames(n int) ([]string, error)

Readdirnames implements afero.File.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek implements afero.File.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat implements afero.File.

func (*File) Sync

func (f *File) Sync() error

Sync implements afero.File.

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate implements afero.File.

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

Write implements afero.File.

func (*File) WriteAt

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

WriteAt implements afero.File.

func (*File) WriteString

func (f *File) WriteString(s string) (ret int, err error)

WriteString implements afero.File.

type FileInfo

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

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

IsDir implements fs.FileInfo.

func (*FileInfo) ModTime

func (f *FileInfo) ModTime() time.Time

ModTime implements fs.FileInfo.

func (*FileInfo) Mode

func (f *FileInfo) Mode() fs.FileMode

Mode implements fs.FileInfo.

func (*FileInfo) Name

func (f *FileInfo) Name() string

Name implements fs.FileInfo.

func (*FileInfo) Size

func (f *FileInfo) Size() int64

Size implements fs.FileInfo.

func (*FileInfo) Sys

func (f *FileInfo) Sys() any

Sys implements fs.FileInfo.

type Fs

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

Fs implements afero.Fs as a write-only filesystem backed by an archive/tar.Writer.

It is intended for creating tar archive entries via standard filesystem-style calls such as Create and OpenFile. Read, stat-based modification, and mutating operations (for example Chmod, Chown, Chtimes, Remove, RemoveAll, and Rename) are not supported on the underlying tar stream and will return appropriate permission or read-only filesystem errors (for example syscall.EPERM or syscall.EROFS).

Callers should treat Fs as an append-only view of a tar archive and should not expect to be able to read back or modify previously written entries through this interface.

func (*Fs) Chmod

func (f *Fs) Chmod(name string, mode os.FileMode) error

Chmod implements afero.Fs.

func (*Fs) Chown

func (f *Fs) Chown(name string, uid int, gid int) error

Chown implements afero.Fs.

func (*Fs) Chtimes

func (f *Fs) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes implements afero.Fs.

func (*Fs) Create

func (f *Fs) Create(name string) (afero.File, error)

Create implements afero.Fs.

func (*Fs) Mkdir

func (f *Fs) Mkdir(name string, perm os.FileMode) error

Mkdir implements afero.Fs.

func (*Fs) MkdirAll

func (f *Fs) MkdirAll(path string, perm os.FileMode) error

MkdirAll implements afero.Fs.

func (*Fs) Name

func (f *Fs) Name() string

Name implements afero.Fs.

func (*Fs) Open

func (f *Fs) Open(name string) (afero.File, error)

Open implements afero.Fs.

func (*Fs) OpenFile

func (f *Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

OpenFile implements afero.Fs.

func (*Fs) Remove

func (f *Fs) Remove(name string) error

Remove implements afero.Fs.

func (*Fs) RemoveAll

func (f *Fs) RemoveAll(path string) error

RemoveAll implements afero.Fs.

func (*Fs) Rename

func (f *Fs) Rename(oldname string, newname string) error

Rename implements afero.Fs.

func (*Fs) Stat

func (f *Fs) Stat(name string) (os.FileInfo, error)

Stat implements afero.Fs.

Jump to

Keyboard shortcuts

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