file

package
v1.40.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1 << (10 * iota)
	MB
	GB
)

Variables

View Source
var (
	ErrNonArchiveSource = fmt.Errorf("non-archive sources are not supported for directory destinations")
)

Functions

func CleanDigestAlgorithmName added in v0.85.0

func CleanDigestAlgorithmName(name string) string

func ContentsFromZip

func ContentsFromZip(ctx context.Context, archivePath string, paths ...string) (map[string]string, error)

ContentsFromZip extracts select paths for the given archive and returns a set of string contents for each path.

func ExtractFromZipToUniqueTempFile

func ExtractFromZipToUniqueTempFile(ctx context.Context, archivePath, dir string, paths ...string) (map[string]Opener, error)

ExtractFromZipToUniqueTempFile extracts select paths for the given archive to a temporary directory, returning file openers for each file extracted.

func ExtractGlobsFromTarToUniqueTempFile added in v0.35.0

func ExtractGlobsFromTarToUniqueTempFile(ctx context.Context, archivePath, dir string, globs ...string) (map[string]Opener, error)

ExtractGlobsFromTarToUniqueTempFile extracts paths matching the given globs within the given archive to a temporary directory, returning file openers for each file extracted.

func Hashers added in v0.85.0

func Hashers(names ...string) ([]crypto.Hash, error)

func IdentifyArchive added in v1.38.1

func IdentifyArchive(ctx context.Context, path string, r io.Reader) (archives.Format, io.Reader, error)

IdentifyArchive is a wrapper around archives.Identify that handles compound extension aliases (like .tgz -> .tar.gz) transparently. It first attempts filename-based detection using the alias map, and falls back to content-based detection if needed.

This function is a drop-in replacement for archives.Identify that centralizes the compound alias handling logic in one place.

func NewDigestsFromFile added in v0.85.0

func NewDigestsFromFile(ctx context.Context, closer io.ReadCloser, hashes []crypto.Hash) ([]file.Digest, error)

func NormalizeHashes added in v0.101.1

func NormalizeHashes(hashes []crypto.Hash) []crypto.Hash

func SafeJoin added in v1.38.0

func SafeJoin(prefix string, dest ...string) (string, error)

SafeJoin ensures that any destinations do not resolve to a path above the prefix path.

func TraverseFilesInTar added in v1.38.0

func TraverseFilesInTar(ctx context.Context, archivePath string, visitor archives.FileHandler) error

TraverseFilesInTar enumerates all paths stored within a tar archive using the visitor pattern.

func TraverseFilesInZip

func TraverseFilesInZip(ctx context.Context, archivePath string, visitor archives.FileHandler, paths ...string) error

TraverseFilesInZip enumerates all paths stored within a zip archive using the visitor pattern.

func UnzipToDir

func UnzipToDir(ctx context.Context, archivePath, targetDir string) error

UnzipToDir extracts a zip archive to a target directory.

func WalkDiskDir added in v1.28.0

func WalkDiskDir(fsys filesystem.FileSystem, root string, fn WalkDiskDirFunc) error

WalkDiskDir walks the file tree within the go-diskfs filesystem at root, calling fn for each file or directory in the tree, including root. This is meant to mimic the behavior of fs.WalkDir in the standard library.

Types

type Getter added in v1.28.0

type Getter interface {
	// GetFile downloads the give URL into the given path. The URL must reference a single file.
	GetFile(dst, src string, monitor ...*progress.Manual) error

	// GetToDir downloads the resource found at the `src` URL into the given `dst` directory.
	// The directory must already exist, and the remote resource MUST BE AN ARCHIVE (e.g. `.tar.gz`).
	GetToDir(dst, src string, monitor ...*progress.Manual) error
}

type HashiGoGetter added in v1.28.0

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

func NewGetter added in v1.28.0

func NewGetter(id clio.Identification, httpClient *http.Client) *HashiGoGetter

NewGetter creates and returns a new Getter. Providing an http.Client is optional. If one is provided, it will be used for all HTTP(S) getting; otherwise, go-getter's default getters will be used.

func (HashiGoGetter) GetFile added in v1.28.0

func (g HashiGoGetter) GetFile(dst, src string, monitors ...*progress.Manual) error

func (HashiGoGetter) GetToDir added in v1.28.0

func (g HashiGoGetter) GetToDir(dst, src string, monitors ...*progress.Manual) error

type Opener added in v0.4.0

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

Opener is an object that stores a path to later be opened as a file.

func (Opener) Open added in v0.4.0

func (o Opener) Open() (io.ReadCloser, error)

Open the stored path as a io.ReadCloser.

type WalkDiskDirFunc added in v1.28.0

type WalkDiskDirFunc func(fsys filesystem.FileSystem, path string, d os.FileInfo, err error) error

type ZipFileManifest

type ZipFileManifest map[string]os.FileInfo

ZipFileManifest is a collection of paths and their file metadata.

func NewZipFileManifest

func NewZipFileManifest(ctx context.Context, archivePath string) (ZipFileManifest, error)

NewZipFileManifest creates and returns a new ZipFileManifest populated with path and metadata from the given zip archive path.

func (ZipFileManifest) Add

func (z ZipFileManifest) Add(entry string, info os.FileInfo)

Add a new path and it's file metadata to the collection.

func (ZipFileManifest) GlobMatch

func (z ZipFileManifest) GlobMatch(caseInsensitive bool, patterns ...string) []string

GlobMatch returns the path keys to files (not directories) that match the given value(s).

Jump to

Keyboard shortcuts

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