Documentation
¶
Overview ¶
Package extract allows to extract archives in zip, tar.gz or tar.bz2 formats easily.
Most of the time you'll just need to call the proper function with a Reader and a destination:
file, _ := os.Open("path/to/file.tar.bz2") extract.Bz2(context.TODO, file, "/path/where/to/extract", nil)
```
Sometimes you'll want a bit more control over the files, such as extracting a subfolder of the archive. In this cases you can specify a renamer func that will change the path for every file:
var shift = func(path string) string { parts := strings.Split(path, string(filepath.Separator)) parts = parts[1:] return strings.Join(parts, string(filepath.Separator)) } extract.Bz2(context.TODO, file, "/path/where/to/extract", shift)
```
If you don't know which archive you're dealing with (life really is always a surprise) you can use Archive, which will infer the type of archive from the first bytes
extract.Archive(context.TODO, file, "/path/where/to/extract", nil)
Index ¶
- func Archive(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func Bz2(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func Gz(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func Tar(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func Xz(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func Zip(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func Zstd(ctx context.Context, body io.Reader, location string, rename Renamer) error
- type Extractor
- func (e *Extractor) Archive(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func (e *Extractor) Bz2(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func (e *Extractor) Gz(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func (e *Extractor) Tar(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func (e *Extractor) Xz(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func (e *Extractor) Zip(ctx context.Context, body io.Reader, location string, rename Renamer) error
- func (e *Extractor) Zstd(ctx context.Context, body io.Reader, location string, rename Renamer) error
- type Renamer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Archive ¶
Archive extracts a generic archived stream of data in the specified location. It automatically detects the archive type and accepts a rename function to handle the names of the files. If the file is not an archive, an error is returned.
func Bz2 ¶
Bz2 extracts a .bz2 or .tar.bz2 archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
func Gz ¶
Gz extracts a .gz or .tar.gz archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
func Tar ¶
Tar extracts a .tar archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
func Xz ¶
Xz extracts a .xz or .tar.xz archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
Types ¶
type Extractor ¶
type Extractor struct { FS interface { // Link creates newname as a hard link to the oldname file. If there is an error, it will be of type *LinkError. Link(oldname, newname string) error // MkdirAll creates the directory path and all his parents if needed. MkdirAll(path string, perm os.FileMode) error // OpenFile opens the named file with specified flag (O_RDONLY etc.). OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) // Symlink creates newname as a symbolic link to oldname. Symlink(oldname, newname string) error // Remove removes the named file or (empty) directory. Remove(path string) error // Stat returns a FileInfo describing the named file. Stat(name string) (os.FileInfo, error) // Chmod changes the mode of the named file to mode. // If the file is a symbolic link, it changes the mode of the link's target. Chmod(name string, mode os.FileMode) error } }
Extractor is more sophisticated than the base functions. It allows to write over an interface rather than directly on the filesystem
func (*Extractor) Archive ¶
func (e *Extractor) Archive(ctx context.Context, body io.Reader, location string, rename Renamer) error
Archive extracts a generic archived stream of data in the specified location. It automatically detects the archive type and accepts a rename function to handle the names of the files. If the file is not an archive, an error is returned.
func (*Extractor) Bz2 ¶
Bz2 extracts a .bz2 or .tar.bz2 archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
func (*Extractor) Gz ¶
Gz extracts a .gz or .tar.gz archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
func (*Extractor) Tar ¶
Tar extracts a .tar archived stream of data in the specified location. It accepts a rename function to handle the names of the files (see the example)
Directories
¶
Path | Synopsis |
---|---|
This utility is used to generate the archives used as testdata for zipslip vulnerability
|
This utility is used to generate the archives used as testdata for zipslip vulnerability |