engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 39 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine creates, extracts, lists and tests archives.

Index

Constants

This section is empty.

Variables

View Source
var ErrPassword = errors.New("wrong or missing password")

ErrPassword means a password is needed or the one given is wrong.

View Source
var Formats = []Format{
	{Name: "7z", Exts: []string{".7z"}, Kind: Kind7z, Create: true, Encrypt: true, Needs: "7zz", Note: "AES-256, encrypted file names, solid"},
	{Name: "zip", Exts: []string{".zip"}, Kind: KindZip, Create: true, Encrypt: true, Note: "AES-256 or legacy ZipCrypto (via 7zz)"},
	{Name: "tar", Exts: []string{".tar"}, Kind: KindTar, Create: true},
	{Name: "tar.gz", Exts: []string{".tar.gz", ".tgz"}, Kind: KindTar, Codec: "gzip", Create: true},
	{Name: "tar.bz2", Exts: []string{".tar.bz2", ".tbz2", ".tbz"}, Kind: KindTar, Codec: "bzip2", Create: true},
	{Name: "tar.xz", Exts: []string{".tar.xz", ".txz"}, Kind: KindTar, Codec: "xz", Create: true},
	{Name: "tar.zst", Exts: []string{".tar.zst", ".tzst"}, Kind: KindTar, Codec: "zstd", Create: true},
	{Name: "tar.br", Exts: []string{".tar.br"}, Kind: KindTar, Codec: "brotli", Create: true},
	{Name: "tar.lz4", Exts: []string{".tar.lz4"}, Kind: KindTar, Codec: "lz4", Create: true},
	{Name: "tar.lz", Exts: []string{".tar.lz", ".tlz"}, Kind: KindTar, Codec: "lzip", Create: true},
	{Name: "tar.lzma", Exts: []string{".tar.lzma"}, Kind: KindTar, Codec: "lzma", Create: true},
	{Name: "gz", Exts: []string{".gz", ".gzip"}, Kind: KindStream, Codec: "gzip", Create: true, Note: "folders become .tar.gz"},
	{Name: "bz2", Exts: []string{".bz2", ".bzip2"}, Kind: KindStream, Codec: "bzip2", Create: true, Note: "folders become .tar.bz2"},
	{Name: "xz", Exts: []string{".xz"}, Kind: KindStream, Codec: "xz", Create: true, Note: "folders become .tar.xz"},
	{Name: "zst", Exts: []string{".zst", ".zstd"}, Kind: KindStream, Codec: "zstd", Create: true, Note: "folders become .tar.zst"},
	{Name: "br", Exts: []string{".br"}, Kind: KindStream, Codec: "brotli", Create: true, Note: "folders become .tar.br"},
	{Name: "lz4", Exts: []string{".lz4"}, Kind: KindStream, Codec: "lz4", Create: true, Note: "folders become .tar.lz4"},
	{Name: "lz", Exts: []string{".lz", ".lzip"}, Kind: KindStream, Codec: "lzip", Create: true, Note: "folders become .tar.lz"},
	{Name: "lzma", Exts: []string{".lzma"}, Kind: KindStream, Codec: "lzma", Create: true, Note: "folders become .tar.lzma"},
	{Name: "dmg", Exts: []string{".dmg"}, Kind: KindDMG, Create: true, Encrypt: true, Needs: "hdiutil", Note: "AES-256 encrypted disk image, macOS"},
	{Name: "iso", Exts: []string{".iso"}, Kind: KindISO, Create: true, Needs: "hdiutil", Note: "UDF + ISO9660 + Joliet, macOS"},
	{Name: "wim", Exts: []string{".wim", ".swm", ".esd"}, Kind: Kind7z, Create: true, Needs: "7zz", Note: "Windows Imaging"},
	{Name: "aar", Exts: []string{".aar", ".yaa"}, Kind: KindAAR, Create: true, Needs: "aa", Note: "Apple Archive (LZFSE), macOS"},
	{Name: "lrz", Exts: []string{".lrz"}, Kind: KindLrzip, Create: true, Needs: "lrzip", Note: "folders become .tar.lrz"},
	{Name: "age", Exts: []string{".age"}, Kind: KindAge, Create: true, Encrypt: true, Note: "encrypt any file or folder with a passphrase or age keys"},

	{Name: "rar", Exts: []string{".rar", ".cbr"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "zipx", Exts: []string{".zipx"}, Kind: KindZip},
	{Name: "jar", Exts: []string{".jar", ".war", ".ear", ".ipa", ".apk", ".xpi", ".appx", ".msix", ".cbz", ".epub", ".whl", ".nupkg", ".vsix", ".aab"}, Kind: KindZip},
	{Name: "cab", Exts: []string{".cab"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "msi", Exts: []string{".msi", ".msp"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "exe", Exts: []string{".exe"}, Kind: Kind7z, Needs: "7zz", Note: "self-extracting and installer archives"},
	{Name: "cpio", Exts: []string{".cpio"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "cpgz", Exts: []string{".cpgz"}, Kind: KindStream, Codec: "gzip", Note: "gzip-wrapped cpio"},
	{Name: "pax", Exts: []string{".pax"}, Kind: KindTar},
	{Name: "pax.gz", Exts: []string{".pax.gz"}, Kind: KindTar, Codec: "gzip"},
	{Name: "spk", Exts: []string{".spk"}, Kind: KindTar, Note: "Synology package"},
	{Name: "xar", Exts: []string{".xar", ".pkg", ".mpkg"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "xip", Exts: []string{".xip"}, Kind: KindXip, Needs: "xip"},
	{Name: "deb", Exts: []string{".deb", ".udeb"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "rpm", Exts: []string{".rpm"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "Z", Exts: []string{".z", ".taz"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "arj", Exts: []string{".arj"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "lzh", Exts: []string{".lzh", ".lha"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "chm", Exts: []string{".chm"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "vhd", Exts: []string{".vhd", ".vhdx", ".vmdk", ".vdi", ".qcow2", ".img"}, Kind: Kind7z, Needs: "7zz", Note: "disk images"},
	{Name: "squashfs", Exts: []string{".squashfs", ".sfs", ".snap", ".appimage"}, Kind: Kind7z, Needs: "7zz"},
	{Name: "wpress", Exts: []string{".wpress"}, Kind: KindWpress, Note: "All-in-One WP Migration backup"},
	{Name: "cpt", Exts: []string{".cpt"}, Kind: KindUnar, Needs: "unar", Note: "Compact Pro"},
	{Name: "sit", Exts: []string{".sit", ".sitx", ".sea"}, Kind: KindUnar, Needs: "unar", Note: "StuffIt"},
	{Name: "is3", Exts: []string{".is3"}, Kind: KindUnar, Needs: "unar", Note: "InstallShield 3"},
}

Formats is the full table. Order matters for display.

View Source
var SplitPresets = []struct {
	Label string
	Size  string
}{
	{"none", "0"}, {"10 MB (email)", "10m"}, {"25 MB (email)", "25m"}, {"100 MB", "100m"},
	{"650 MB (CD)", "650m"}, {"700 MB (CD)", "700m"}, {"1 GB", "1g"},
	{"4 GB (FAT32)", "4095m"}, {"4.7 GB (DVD)", "4480m"}, {"8.5 GB (DVD DL)", "8100m"}, {"25 GB (Blu-ray)", "23g"},
}

SplitPresets are the sizes offered in the TUI.

Functions

func Compress

func Compress(ctx context.Context, inputs []string, o CompressOptions, cb Progress) ([]string, error)

Compress makes one archive from all inputs, or one per input when o.Separate is set. It returns the files written (volumes included).

func CreateNames

func CreateNames() []string

CreateNames lists the formats pakket can create.

func Extract

func Extract(ctx context.Context, archive string, o ExtractOptions, cb Progress) (string, error)

Extract unpacks an archive and returns where the result went: the single item it contained, the new folder, or the destination folder.

func IsArchive

func IsArchive(path string) bool

IsArchive reports whether pakket would extract this path.

func KeychainDelete

func KeychainDelete(archive string) error

KeychainDelete removes a stored password.

func KeychainFind

func KeychainFind(archive string) (string, bool)

KeychainFind returns a stored password for an archive, if any. It also tries the name without split or extension suffixes.

func KeychainSave

func KeychainSave(archive, password string) error

KeychainSave stores a password for an archive name in the login Keychain.

func Notify

func Notify(title, msg string)

Notify shows a desktop notification (macOS only, best effort).

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize reads sizes like 100m, 4.7g, 650MB, 1440k, 2048 (bytes).

func Parts

func Parts(path string) []string

Parts returns every volume of a split archive given any one of them, or just the path itself.

func StripExt

func StripExt(name string) string

StripExt removes a known archive extension (and split suffix) from a name.

func Test

func Test(ctx context.Context, archive string, o ExtractOptions, cb Progress) error

Test checks that an archive is readable and its checksums match.

func Tool

func Tool(name string) (string, bool)

Tool finds an external program. 7-Zip is looked up as 7zz, then 7z.

func Trash

func Trash(paths ...string) error

Trash moves paths to the Trash: macOS, or gio / trash-cli on Linux. With neither available it deletes them.

Types

type CompressOptions

type CompressOptions struct {
	Format         string   // see CreateNames
	Level          int      // 0 (store) .. 9 (max)
	Password       string   // empty = no encryption
	EncryptNames   bool     // 7z only: hide file names (on by default in the CLI)
	ZipLegacy      bool     // zip: ZipCrypto instead of AES-256
	Solid          bool     // 7z solid block
	ExcludeMac     bool     // skip .DS_Store, ._* and __MACOSX
	Exclude        []string // extra glob patterns, matched on base names
	Separate       bool     // one archive per input
	DeleteAfter    bool     // move inputs to the Trash after success
	SplitSize      int64    // bytes per volume, 0 = no split
	Output         string   // full output path (single archive only)
	DestDir        string   // folder for outputs, default: next to the first input
	Name           string   // archive base name without extension
	VolumeName     string   // dmg / iso
	Checksum       string   // "", "md5", "sha256": write a sidecar file
	ExportPassword bool     // write <archive>.txt with the password
	AgeRecipients  []string // age: public keys or files of keys, used instead of a passphrase
	Overwrite      bool     // replace an existing output instead of picking "name 2"
	Threads        int      // 0 = automatic
}

CompressOptions are the settings for making archives.

type Entry

type Entry struct {
	Name      string    `json:"name"`
	Size      int64     `json:"size"`   // -1 when unknown
	Packed    int64     `json:"packed"` // -1 when unknown
	Modified  time.Time `json:"modified,omitempty"`
	Dir       bool      `json:"dir,omitempty"`
	Encrypted bool      `json:"encrypted,omitempty"`
}

Entry is one item inside an archive.

func List

func List(ctx context.Context, archive string, o ExtractOptions) ([]Entry, error)

List returns the contents of an archive.

type ExtractOptions

type ExtractOptions struct {
	DestDir      string   // default: next to the archive
	Folder       string   // "smart" (default), "always", "never"
	Password     string   // tried when the archive is encrypted
	Passwords    []string // more passwords to try, in order
	DeleteAfter  bool     // move the archive (and its parts) to the Trash after success
	Quarantine   bool     // copy com.apple.quarantine from the archive to its contents
	Encoding     string   // name encoding for old zips: "auto", "cp437", "shift_jis", ...
	Overwrite    string   // "rename" (default), "overwrite", "skip"
	IgnoreGzName bool     // ignore the name stored inside a .gz
	Identities   []string // age identity files
	Nested       bool     // also unpack a single archive found inside (e.g. .tar inside .gz)
}

ExtractOptions are the settings for unpacking archives.

type Format

type Format struct {
	Name    string   // canonical name, used with --format
	Exts    []string // extensions, first is the one used when creating
	Kind    Kind
	Codec   string // stream codec for KindTar / KindStream ("" = plain tar)
	Create  bool   // pakket can create it
	Encrypt bool   // supports a password when creating
	Needs   string // external tool, if any
	Note    string
}

Format describes one archive type.

func ByName

func ByName(name string) (Format, bool)

ByName finds a format by its name or one of its extensions.

func Detect

func Detect(path string) (Format, error)

Detect works out the format of a file from its contents, then its name. Containers that share a magic number (jar, ipa, cpgz, tar.gz ...) are refined by extension.

type Kind

type Kind int

Kind says which code path handles a format.

const (
	KindTar    Kind = iota // tar, optionally wrapped in a stream codec
	KindStream             // a single compressed file
	KindZip                // zip and zip-based containers
	Kind7z                 // handled by the 7zz binary
	KindDMG                // hdiutil
	KindISO                // hdiutil makehybrid / 7zz
	KindAAR                // Apple Archive, /usr/bin/aa
	KindAge                // age encryption
	KindLrzip              // lrzip binary
	KindXip                // /usr/bin/xip
	KindWpress             // All-in-One WP Migration
	KindUnar               // unar binary (old Mac formats)
)

type Progress

type Progress func(done, total int64, current string)

Progress receives updates while a job runs. done and total are bytes; total is 0 when unknown. It may be nil.

Jump to

Keyboard shortcuts

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