Documentation
¶
Overview ¶
Package archive reads archives (RAR, 7-Zip, ZIP, TAR and single compressed files) and unpacks what's asked of them: comics' pages, today.
Archives are treated as hostile. Everything that decodes one runs in a short-lived child process (worker.go), because the decoders can be made to panic or to ask for enormous amounts of memory by a crafted header, and neither of those may take the server down. Nothing here ever writes beside the archive.
Index ¶
Constants ¶
const ( // MaxEntries is far above any comic: a few hundred pages. MaxEntries = 10000 // MaxUnpacked is above several dual-layer discs; the cache's own limit is usually lower. MaxUnpacked = int64(32) << 30 // MaxRatio applies above ratioFloor. Blank space in a disc image compresses // well, but not this well. A small file may be mostly padding. MaxRatio = 2000 )
const ScanBudget = int64(64) << 20
ScanBudget is how much of a compressed tar a scan reads through.
Variables ¶
var ( ErrEncrypted = &Error{"encrypted", "This archive is protected by a password, and this server doesn't open those. Unpack it yourself and put what it holds in the folder."} ErrUnsafe = &Error{"unsafe", "This archive tries to put files outside its own folder, so it was refused."} ErrTooBig = &Error{"toobig", "This archive unpacks to far more than it should, so it was refused."} ErrTooMany = &Error{"toomany", "This archive holds too many files to be read, so it was refused."} ErrDamaged = &Error{"damaged", "This archive is damaged or isn't the kind of file its name says."} ErrMethod = &Error{"method", "This archive uses a kind of compression this server can't read. Unpack it yourself and put what it holds in the folder."} ErrNoSpace = &Error{"nospace", "There isn't enough free disk space to unpack this."} )
Functions ¶
func BaseName ¶
BaseName is an archive's name without what makes it an archive: "Game (USA).tar.gz", "Game (USA).part1.rar" and "Game (USA).7z.001" are all "Game (USA)". Region and dump tags stay.
func IsArchive ¶
IsArchive says whether a file's name is one of the kinds of archive this package reads.
func IsLaterVolume ¶
IsLaterVolume: the second and later parts of a split RAR. They are read through the first part, and aren't archives by themselves.
Types ¶
type Entry ¶
type Entry struct {
Name string `json:"n"`
Size int64 `json:"s"`
// CRC is the file's CRC-32 as the archive records it, or 0 if it doesn't. Game
// databases are keyed on these, so a game can be recognised without unpacking it.
CRC uint32 `json:"c,omitempty"`
}
An Entry is one regular file in an archive. Size is -1 when the archive doesn't say.
type Error ¶
An Error is why an archive can't be used, in words for the owner. The Code stays the same across the pipe from the worker, and into the scan's report.
type Lister ¶
type Lister struct {
// contains filtered or unexported fields
}
A Lister reads archive headers one after another through one worker, so a scan of thousands costs one process and not thousands. A crash or a hang costs only the archive that caused it: that one is reported as damaged, and the next gets a new worker. Not for use by several goroutines at once.
type Listing ¶
A Listing is what an archive holds, read from its headers. Partial: a .tar.gz has no index, so a scan looks only so far into one.
type Want ¶
A Want is one file to unpack: Name is its name in the archive, Out its name in the folder (relative, already checked by the caller).