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.
- arj - open-source ARJ v3.10
- lha - Lhasa v0.4 LHA tool found in the jlha-utils or lhasa packages
- unrar - 6.24 freeware by Alexander Roshal, not the common unrar-free which is feature incomplete
- zipinfo - ZipInfo v3 by the Info-ZIP workgroup
Index ¶
- Variables
- func CheckyPath(p []byte) string
- func Extract(src, dst, filename string, targets ...string) error
- func List(src, filename string) ([]string, error)
- func MagicExt(src string) (string, error)
- func Readme(filename string, files ...string) string
- func Replace(ext, filename string) string
- type Content
- type Extractor
- type Finds
- type Usability
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
List returns the files within an rar, tar, lha, or zip archive. This filename extension is used to determine the archive format.
func MagicExt ¶
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 ¶
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.
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 ¶
ARJ returns the content of the src ARJ archive, credited to Robert Jung, using the arj program.
func (*Content) LHA ¶
LHA returns the content of the src LHA or LZH archive, credited to Haruyasu Yoshizaki (Yoshi), using the lha program.
func (*Content) Rar ¶
Rar returns the content of the src RAR archive, credited to Alexander Roshal, using the unrar 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 ¶
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 ¶
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.