extract

package
v0.0.0-...-950aede Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package extract provides archive extraction helpers.

Index

Constants

View Source
const (
	// ExtractToTempDir is a sentinel destination value that will cause
	// [Extract] to generate a temporary directory for extraction, and remove
	// the temporary directory once extraction (and callbacks) have completed.
	// ExtractToTempDir is only useful if a [Callback] is passed to Extract.
	ExtractToTempDir = ""
)

Variables

This section is empty.

Functions

func Extract

func Extract(
	ctx context.Context,
	dst string,
	archive string,
	opts ...Option,
) (err error)

Extract extracts the given archive to dst using any provided [Option]s.

Types

type Callback

type Callback func(ctx context.Context, path string) error

A Callback is a function called by Extract once an archive has been extracted. When called, the current working directory is the extract destination, and is also passed as the path parameter.

type Option

type Option interface {
	// contains filtered or unexported methods
}

An Option configures the behavior of Extract.

func Delete

func Delete(del bool) Option

Delete returns a new Option that configures Extract to delete any archive directories from the destination before extracting them.

func ExcludePaths

func ExcludePaths(paths []string) Option

ExcludePaths returns a new Option that configures Extract to exclude any matching paths from extraction. The given paths should be relative to either the archive root or the stripped prefix, and may be globs.

func IncludePaths

func IncludePaths(paths map[string]string) Option

IncludePaths returns a new Option that configures Extract to only consider the given paths for extraction. The given map's keys should be relative to either the archive root or the stripped prefix, and may be globs; the map's values are optional and specify non-default destinations for any path(s) matched by the corresponding key.

func Output

func Output(output io.Writer) Option

Output returns a new Option that configures Extract to write any output to the given writer.

func StripPrefix

func StripPrefix(prefix string) Option

StripPrefix returns a new Option that configures Extract to root all extraction at the given prefix. Note that paths that are not descendants of the given prefix will not be extracted.

type Options

type Options struct {
	Callback     Callback
	Output       io.Writer
	StripPrefix  string
	IncludePaths map[string]string
	ExcludePaths []string
	Delete       bool
}

Options configure the behavior of Extract.

func (Options) With

func (o Options) With(opts ...Option) Options

With returns a new Options with opts merged on top of o.

Jump to

Keyboard shortcuts

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