Documentation
¶
Overview ¶
Package archivefs presents an archive as the folder it was made from (agni issue 1591). A zip, a tar or a 7z holds many named files, so it reads as a directory of the same name. A tar is usually wrapped in a stream compressor, gzip, bzip2, xz or zstd, which is a content encoding of one stream, so it is peeled off first and the tar inside chosen by its bytes. No reader knows an archive was involved. A reader that spans files, such as an ODB++ job or a KiCad hierarchy, reads the folder as it reads any other.
An archive is hostile input (C1). Every container kind is held to the same bounds while it decodes: MaxMembers files, MaxMemberBytes for any one file, and MaxExpandedBytes in all. A member whose path climbs out of the archive is read from inside it, and an encrypted archive fails with ErrEncrypted.
Index ¶
- Constants
- Variables
- func Candidate(name string) bool
- func Container(name string) string
- func Expand(fsys fs.FS) fs.FS
- func Gunzip(b []byte) ([]byte, error)
- func IsArchiveFile(name string) bool
- func OSMembers(name string) (fs.FS, error)
- func OSOpen(name string) (fs.File, error)
- func OSReadDir(name string) ([]fs.DirEntry, error)
- func OSReadFile(name string) ([]byte, error)
- func OSStat(name string) (fs.FileInfo, error)
- func Open(b []byte) (fs.FS, error)
- func Sniff(head []byte) bool
Constants ¶
const ( MaxExpandedBytes = 1 << 30 MaxMemberBytes = 1 << 29 MaxMembers = 100_000 )
The bounds every archive is held to. An ODB++ job is text, and a large board's job runs to a few hundred megabytes, so a gigabyte in all leaves room and still refuses a decompression bomb.
Variables ¶
var ( // ErrNotArchive says the bytes are no container this package reads. A compressed stream that // holds one file rather than a tar is not an archive either. ErrNotArchive = errors.New("archivefs: not a zip, tar or 7z archive") // ErrEncrypted says the archive needs a password, which agni never has. ErrEncrypted = errors.New("archivefs: the archive is encrypted") // ErrTooLarge says the archive expands past MaxExpandedBytes, or a member past MaxMemberBytes. ErrTooLarge = errors.New("archivefs: the archive expands past its bound") // ErrTooMany says the archive holds more than MaxMembers files. ErrTooMany = errors.New("archivefs: the archive holds too many files") )
Functions ¶
func Container ¶
Container returns the archive file a host path runs through, or "" when the path names a file or directory of its own. A record of what a read touched stamps the archive, since its members have no stamp of their own on the host filesystem.
func Expand ¶
Expand presents every archive in fsys as a directory of the same name holding the archive's members. It nests, so an archive inside an archive is a directory too. A file that has an archive's name and does not open as one stays a file. An archive is read whole on first use and kept.
func Gunzip ¶
Gunzip decodes one gzip stream, held to MaxMemberBytes. A format that gzips single members, as an ODB++ job may, decodes them through it.
func IsArchiveFile ¶
IsArchiveFile reports whether the host file at name starts as an archive does. It reads the file's first bytes alone, so a listing of a folder of large archives opens none of them. A file that starts like one and does not open fails when it is read.
func OSMembers ¶
OSMembers is the archive file at a host path as the folder it was made from. It is kept while the file is unchanged.
func OSOpen ¶
OSOpen opens a host path as os.Open does, and through an archive where the path runs into one. An archive file itself opens as a file, as os.Open opens it.
func OSReadDir ¶
OSReadDir lists a host directory as os.ReadDir does, with each archive listed as a directory, and lists inside an archive where the path runs into or names one.
func OSReadFile ¶
OSReadFile reads a host path as os.ReadFile does, and through an archive where the path runs into one.
func OSStat ¶
OSStat stats a host path as os.Stat does, and through an archive where the path runs into one. An archive file stats as the directory it reads as.
Types ¶
This section is empty.