file

package
v0.0.0-...-0710af2 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func CleanDigestAlgorithmName

func CleanDigestAlgorithmName(name string) string

func ContentsFromZip

func ContentsFromZip(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(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

func ExtractGlobsFromTarToUniqueTempFile(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 GlobMatch

func GlobMatch(pattern, name string) bool

GlobMatch evaluates the given glob pattern against the given "name" string, indicating if there is a match or not. Source: https://research.swtch.com/glob.go

func Hashers

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

func NewDigestsFromFile

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

func TraverseFilesInZip

func TraverseFilesInZip(archivePath string, visitor func(*zip.File) error, paths ...string) error

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

func UnzipToDir

func UnzipToDir(archivePath, targetDir string) error

UnzipToDir extracts a zip archive to a target directory.

Types

type Opener

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

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

Open the stored path as a io.ReadCloser.

type ZipFileManifest

type ZipFileManifest map[string]os.FileInfo

ZipFileManifest is a collection of paths and their file metadata.

func NewZipFileManifest

func NewZipFileManifest(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(patterns ...string) []string

GlobMatch returns the path keys that match the given value(s).

type ZipReadCloser

type ZipReadCloser struct {
	*zip.Reader
	io.Closer
}

ZipReadCloser is a drop-in replacement for zip.ReadCloser (from zip.OpenReader) that additionally considers zips that have bytes prefixed to the front of the archive (common with self-extracting jars).

func OpenZip

func OpenZip(filepath string) (*ZipReadCloser, error)

OpenZip provides a ZipReadCloser for the given filepath.

Jump to

Keyboard shortcuts

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