extract

package
v0.1.7-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package extract provides utilities for extracting zip files.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidArchive = errors.New("invalid archive")

ErrInvalidArchive indicates the archive is invalid or contains unsafe entries.

Functions

func GetZipRootDirectory

func GetZipRootDirectory(zipPath string) (string, error)

GetZipRootDirectory returns the common root directory of all files in the ZIP. XenForo ZIPs typically have all files under an "upload/" directory.

func XenForoZip

func XenForoZip(zipPath, destDir string, onProgress func(current, total int, filename string)) error

XenForoZip extracts a XenForo ZIP file to the destination. It extracts only files from within the "upload/" directory, stripping that prefix. This handles XenForo's ZIP structure where files are under upload/ but there may be other files like README at the root.

func ZipFile

func ZipFile(zipPath, destDir string, opts *Options) error

ZipFile extracts a zip archive to a destination directory with optional processing.

Types

type Options

type Options struct {
	// StripComponents removes this many leading path components from extracted files.
	// For example, if StripComponents=1 and the archive contains "upload/src/XF.php",
	// it will be extracted as "src/XF.php".
	StripComponents int

	// OverwriteExisting allows overwriting existing files.
	OverwriteExisting bool

	// PreservePermissions preserves file permissions from the archive.
	PreservePermissions bool

	// OnProgress is called for each file extracted (if set).
	OnProgress func(current, total int, filename string)
}

Options configures the extraction behavior.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default extraction options.

type ZipInfo

type ZipInfo struct {
	Path          string
	FileCount     int
	DirCount      int
	TotalSize     uint64
	RootDirectory string
}

ZipInfo contains information about a ZIP archive.

Jump to

Keyboard shortcuts

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