archivefs

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 Candidate

func Candidate(name string) bool

Candidate reports whether a name is one a host should try to open as an archive.

func Container

func Container(name string) string

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

func Expand(fsys fs.FS) fs.FS

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

func Gunzip(b []byte) ([]byte, error)

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

func IsArchiveFile(name string) bool

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

func OSMembers(name string) (fs.FS, error)

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

func OSOpen(name string) (fs.File, error)

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

func OSReadDir(name string) ([]fs.DirEntry, error)

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

func OSReadFile(name string) ([]byte, error)

OSReadFile reads a host path as os.ReadFile does, and through an archive where the path runs into one.

func OSStat

func OSStat(name string) (fs.FileInfo, error)

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.

func Open

func Open(b []byte) (fs.FS, error)

Open presents an archive's bytes as a file system holding its members. The archive's kind comes from its bytes. A zip reads its members on demand. Every other kind decodes whole into memory, since a tar and a solid 7z can only be read from the front.

func Sniff

func Sniff(head []byte) bool

Sniff reports whether bytes start as an archive or a compressed stream does, from their first block alone. A compressed stream may still hold one file rather than a tar, which Open refuses.

Types

This section is empty.

Jump to

Keyboard shortcuts

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