archive

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package archive provides compressed and stored archive file extraction and content listing.

The file archive formats supported are ARJ, LHA, LZH, RAR, TAR, and ZIP.

The package uses the mholt/archiver/v3 package and the following Linux programs as a fallback for legacy file support.

  1. arj - open-source ARJ v3.10
  2. lha - Lhasa v0.4 LHA tool found in the jlha-utils or lhasa packages
  3. unrar - 6.24 freeware by Alexander Roshal, not the common unrar-free which is feature incomplete
  4. zipinfo - ZipInfo v3 by the Info-ZIP workgroup

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDest    = errors.New("destination is empty")
	ErrExt     = errors.New("extension is not a supported archive format")
	ErrRead    = errors.New("could not read the file archive")
	ErrProg    = errors.New("program error")
	ErrFile    = errors.New("path is a directory")
	ErrPath    = errors.New("path is a file")
	ErrPanic   = errors.New("extract panic")
	ErrMissing = errors.New("path does not exist")
)

Functions

func CheckyPath

func CheckyPath(p []byte) string

CheckyPath checks the byte slice for valid UTF-8 encoding. If the byte slice is not valid, it will attempt to decode the byte slice using the MS-DOS, charmap.CodePage437 character set.

Needed for historical oddities found in BBS file archives, the file and folders were sometimes named in leetspeak using untypable characters and symbols. For example the valid filename ¿ædmé.ñôw could not be easily typed out on a standard North American keyboard in MS-DOS.

func Extract

func Extract(src, dst, filename string, targets ...string) error

Extract the filename targets from the source archive file to the destination folder. If no targets are provided, all files are extracted. The filename extension is used to determine the archive format.

func List

func List(src, filename string) ([]string, error)

List returns the files within an rar, tar, lha, or zip archive. This filename extension is used to determine the archive format.

func MagicExt

func MagicExt(src string) (string, error)

MagicExt uses the Linux file program to determine the src archive file type. The returned string will be a file separator and extension. For example a file with the magic string "gzip compressed data" will return ".tar.gz".

Note both bzip2 and gzip archives return the .tar extension prefix.

func Readme

func Readme(filename string, files ...string) string

Readme returns the best matching scene text README or NFO file from a collection of files. The filename is the name of the archive file, and the files are the list of files in the archive. Note the filename matches are case-insensitive as many handled file archives are created on Windows FAT32, NTFS or MS-DOS FAT16 file systems.

func Replace

func Replace(ext, filename string) string

Replace the filename file extension with the ext string. Leaving ext empty returns the filename without a file extension.

Types

type Content

type Content struct {
	Ext   string   // Ext returns file extension of the archive.
	Files []string // Files returns list of files within the archive.
}

Content are the result of using system programs to read the file archives.

func (*Content) ARJ

func (c *Content) ARJ(src string) error

ARJ returns the content of the src ARJ archive, credited to Robert Jung, using the arj program.

func (*Content) LHA

func (c *Content) LHA(src string) error

LHA returns the content of the src LHA or LZH archive, credited to Haruyasu Yoshizaki (Yoshi), using the lha program.

func (*Content) Rar

func (c *Content) Rar(src string) error

Rar returns the content of the src RAR archive, credited to Alexander Roshal, using the unrar program.

func (*Content) Read

func (c *Content) Read(src string) error

Read returns the content of the src file archive using the system archiver programs. The filename is used to determine the archive format. Supported formats are ARJ, LHA, LZH, RAR, and ZIP.

func (*Content) Zip

func (c *Content) Zip(src string) error

Zip returns the content of the src ZIP archive, credited to Phil Katz, using the zipinfo program.

type Extractor

type Extractor struct {
	Source      string // The source archive file.
	Destination string // The extraction destination directory.

	// The original filename of the archive, used by Extract to determine the archive format.
	Filename string
}

Extractor uses system archiver programs to extract the targets from the src file archive.

func (Extractor) ARJ

func (x Extractor) ARJ(targets ...string) error

ARJ extracts the targets from the source ARJ archive to the destination directory using the arj program. If the targets are empty then all files are extracted.

func (Extractor) Extract

func (x Extractor) Extract(targets ...string) error

Extract the targets from the source file archive to the destination directory a system archive program. If the targets are empty then all files are extracted.

The required Filename string is used to determine the archive format.

func (Extractor) LHA

func (x Extractor) LHA(targets ...string) error

LHA extracts the targets from the source LHA/LZH archive to the destination directory using an lha program. If the targets are empty then all files are extracted.

On Linux either the jlha-utils or lhasa work.

func (Extractor) Zip

func (x Extractor) Zip(targets ...string) error

Zip extracts the targets from the source Zip archive to the destination directory using the unzip program. If the targets are empty then all files are extracted.

type Finds

type Finds map[string]Usability

Finds are a collection of matched filenames and their usability ranking.

func (Finds) BestMatch

func (f Finds) BestMatch() string

BestMatch returns the most usable filename from a collection of finds.

type Usability

type Usability uint

Usability of search, filename pattern matches.

const (
	// Lvl1 is the highest usability.
	Lvl1 Usability = iota + 1
	Lvl2
	Lvl3
	Lvl4
	Lvl5
	Lvl6
	Lvl7
	Lvl8
	Lvl9 // Lvl9 is the least usable.
)

Directories

Path Synopsis
Package internal contains the internal functions for the archive package.
Package internal contains the internal functions for the archive package.

Jump to

Keyboard shortcuts

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