extractor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(e Extractor)

Register adds an extractor to the registry.

Types

type Bz2Extractor

type Bz2Extractor struct{}

Bz2Extractor handles bzip2-compressed input (both .tar.bz2 and standalone .bz2)

func (*Bz2Extractor) Detect

func (b *Bz2Extractor) Detect(header []byte) bool

func (*Bz2Extractor) Extract

func (b *Bz2Extractor) Extract(src, destDir string) error

func (*Bz2Extractor) List

func (b *Bz2Extractor) List(src string) ([]string, error)

func (*Bz2Extractor) Name

func (b *Bz2Extractor) Name() string

type Extractor

type Extractor interface {
	// Detect reports whether the given header bytes match this format's magic signature.
	Detect(header []byte) bool

	// Extract unpacks the archive at src into destDir.
	Extract(src, destDir string) error

	// List returns the names of entries inside the archive without extracting them.
	List(src string) ([]string, error)

	// Name returns the format identifier ("zip", "gzip", etc).
	Name() string
}

Extractor is implemented by every supported archive format.

func DetectExtractor

func DetectExtractor(header []byte) Extractor

DetectExtractor finds the extractor whose Detect matches the given header bytes.

func Get

func Get(name string) (Extractor, bool)

Get returns a registered extractor by name.

type GzExtractor

type GzExtractor struct{}

GzExtractor handles gzip-compressed input (both .tar.gz and standalone .gz)

func (*GzExtractor) Detect

func (g *GzExtractor) Detect(header []byte) bool

func (*GzExtractor) Extract

func (g *GzExtractor) Extract(src, destDir string) error

func (*GzExtractor) List

func (g *GzExtractor) List(src string) ([]string, error)

func (*GzExtractor) Name

func (g *GzExtractor) Name() string

type RarExtractor

type RarExtractor struct{}

RarExtractor implements the Extractor interface for RAR archives by shelling out to the system's "unrar" binary, since no reliable pure-Go RAR writer/extractor exists.

func (*RarExtractor) Detect

func (r *RarExtractor) Detect(header []byte) bool

Detect checks for the RAR magic signature (first 6 bytes, shared by RAR4 and RAR5)

func (*RarExtractor) Extract

func (r *RarExtractor) Extract(src, destDir string) error

Extract unpacks the RAR archive at src into destDir using the external unrar binary.

func (*RarExtractor) List

func (r *RarExtractor) List(src string) ([]string, error)

List returns the names of entries inside the RAR archive without extracting them, using "unrar lb" (bare listing mode: one filename per line).

func (*RarExtractor) Name

func (r *RarExtractor) Name() string

type SevenZipExtractor

type SevenZipExtractor struct{}

SevenZipExtractor implements the Extractor interface for 7z archives

func (*SevenZipExtractor) Detect

func (s *SevenZipExtractor) Detect(header []byte) bool

func (*SevenZipExtractor) Extract

func (s *SevenZipExtractor) Extract(src, destDir string) error

func (*SevenZipExtractor) List

func (s *SevenZipExtractor) List(src string) ([]string, error)

func (*SevenZipExtractor) Name

func (s *SevenZipExtractor) Name() string

type TarExtractor

type TarExtractor struct{}

TarExtractor implements the Extractor interface for plain (uncompressed) tar archives

func (*TarExtractor) Detect

func (t *TarExtractor) Detect(header []byte) bool

func (*TarExtractor) Extract

func (t *TarExtractor) Extract(src, destDir string) error

func (*TarExtractor) List

func (t *TarExtractor) List(src string) ([]string, error)

func (*TarExtractor) Name

func (t *TarExtractor) Name() string

type XzExtractor

type XzExtractor struct{}

XzExtractor handles xz-compressed input (both .tar.xz and standalone .xz)

func (*XzExtractor) Detect

func (x *XzExtractor) Detect(header []byte) bool

func (*XzExtractor) Extract

func (x *XzExtractor) Extract(src, destDir string) error

func (*XzExtractor) List

func (x *XzExtractor) List(src string) ([]string, error)

func (*XzExtractor) Name

func (x *XzExtractor) Name() string

type ZipExtractor

type ZipExtractor struct{}

ZipExtractor implements the Extractor interface for standard zip archives

func (*ZipExtractor) Detect

func (z *ZipExtractor) Detect(header []byte) bool

func (*ZipExtractor) Extract

func (z *ZipExtractor) Extract(src, destDir string) error

func (*ZipExtractor) List

func (z *ZipExtractor) List(src string) ([]string, error)

List returns the names of all entries in the zip archive without extracting them.

func (*ZipExtractor) Name

func (z *ZipExtractor) Name() string

type ZstExtractor

type ZstExtractor struct{}

ZstExtractor handles zstd-compressed input (both .tar.zst and standalone .zst)

func (*ZstExtractor) Detect

func (z *ZstExtractor) Detect(header []byte) bool

func (*ZstExtractor) Extract

func (z *ZstExtractor) Extract(src, destDir string) error

func (*ZstExtractor) List

func (z *ZstExtractor) List(src string) ([]string, error)

func (*ZstExtractor) Name

func (z *ZstExtractor) Name() string

Jump to

Keyboard shortcuts

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