archive

package
v0.0.64 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0, NCSA Imports: 9 Imported by: 0

Documentation

Overview

Package archive provides support for reading the contents of archives such as .zip and .tar files.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotArchive = errors.New("not a supported archive file")

ErrNotArchive is returned by Scan when passed a file it does not recognize as a readable archive.

Functions

func Scan

func Scan(file File, path string, f ScanFunc) error

Scan sequentially scans the contents of an archive and invokes f for each file found. If f returns an error, scanning stops and that error is returned to the caller of Scan. The path is used to determine what type of archive is referred to by file. If the type is not known, it returns ErrNotArchive.

The supported archive formats are:

.zip     -- ZIP archive (also .ZIP, .jar)
.tar     -- uncompressed tar
.tar.gz  -- gzip-compressed tar (also .tgz)
.tar.bz2 -- bzip2-compressed tar

Scan only invokes f for file entries; directories are not included.

Types

type File

type File interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
}

File defines the input capabilities needed to scan an archive file.

type ScanFunc

type ScanFunc func(filename string, err error, r io.Reader) error

A ScanFunc is invoked by the Scan function for each file found in the specified archive. The arguments are the filename as encoded in the archive, and either an error or a reader positioned at the beginning of the file's contents.

Any error returned by the ScanFunc is propagated to the caller of Scan, terminating the traversal of the archive. The callback may choose to ignore err, in which case the error is ignored and scanning continues.

Jump to

Keyboard shortcuts

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