Documentation
¶
Overview ¶
Package archives provides in-memory archive reading and browsing capabilities.
It supports multiple archive formats including:
- ZIP (.zip, .jar, .whl, .nupkg)
- TAR (.tar, .tar.gz, .tgz, .tar.bz2, .tar.xz)
- GEM (.gem - Ruby gems with nested tar structure)
The package is designed to work entirely in memory without writing to disk, making it suitable for browsing cached artifacts on-demand.
Index ¶
- Constants
- Variables
- type FileInfo
- type Reader
- func Open(filename string, content io.Reader) (Reader, error)
- func OpenBytes(filename string, content []byte) (Reader, error)
- func OpenBytesWithPrefix(filename string, content []byte, stripPrefix string) (Reader, error)
- func OpenWithPrefix(filename string, content io.Reader, stripPrefix string) (Reader, error)
Constants ¶
const ( SHA256 = "sha256" SHA512 = "sha512" SHA1 = "sha1" MD5 = "md5" )
Supported hash algorithm names for Reader.Hash.
Variables ¶
var ErrDecompressLimit = errors.New("decompressed content exceeds size limit")
Functions ¶
This section is empty.
Types ¶
type FileInfo ¶
type FileInfo struct {
Path string // Full path within archive
Name string // Base name
Size int64 // Uncompressed size in bytes
ModTime time.Time // Modification time
IsDir bool // Whether this is a directory
Mode uint32 // File mode/permissions
CompressedSize int64 // Compressed size (if available)
}
FileInfo represents metadata about a file in an archive.
type Reader ¶
type Reader interface {
// List returns all files in the archive.
List() ([]FileInfo, error)
// ListDir returns files in a specific directory path.
// Use "" or "/" for root directory.
ListDir(dirPath string) ([]FileInfo, error)
// Extract reads a specific file from the archive.
// Returns io.ReadCloser for the file content.
Extract(filePath string) (io.ReadCloser, error)
// Hash returns the hex-encoded digest of the raw archive bytes using
// the named algorithm. Supported algorithms are SHA256, SHA512, SHA1
// and MD5. The hash is computed over the original archive as passed
// to Open, not the decompressed contents.
Hash(algo string) (string, error)
// Close releases resources associated with the reader.
Close() error
}
Reader provides methods to browse and extract files from archives.
func Open ¶
Open creates an archive reader for the given content. The filename is used to detect the archive format. The content reader will be read entirely into memory.
func OpenBytes ¶ added in v0.3.0
OpenBytes is like Open but accepts the archive content as a byte slice. The slice is retained (not copied) for the lifetime of the Reader and must not be modified by the caller after this call.
func OpenBytesWithPrefix ¶ added in v0.3.0
OpenBytesWithPrefix is like OpenWithPrefix but accepts the archive content as a byte slice. The slice is retained (not copied) for the lifetime of the Reader and must not be modified by the caller after this call.