Package tarutil implements some tar utility functions.
var ( // ErrCouldNotExtract occurs when an extraction fails. ErrCouldNotExtract = errors.New("tarutil: could not extract the archive") // ErrExtractedFileTooBig occurs when a file to extract is too big. ErrExtractedFileTooBig = errors.New("tarutil: could not extract one or more files from the archive: file too big") // MaxExtractableFileSize enforces the maximum size of a single file within a // tarball that will be extracted. This protects against malicious files that // may used in an attempt to perform a Denial of Service attack. MaxExtractableFileSize int64 = 200 * 1024 * 1024 // 200 MiB )
FilesMap is a map of files' paths to their contents.
ExtractFiles decompresses and extracts only the specified files from an io.Reader representing an archive. The files to be extracted are specified by regexp
TarReadCloser embeds a *tar.Reader and the related io.Closer It is the caller's responsibility to call Close on TarReadCloser when done.
NewTarReadCloser attempts to detect the compression algorithm for an io.Reader and returns a TarReadCloser wrapping the Reader to transparently decompress the contents.
Gzip/Bzip2/XZ detection is done by using the magic numbers: Gzip: the first two bytes should be 0x1f and 0x8b. Defined in the RFC1952. Bzip2: the first three bytes should be 0x42, 0x5a and 0x68. No RFC. XZ: the first three bytes should be 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00. No RFC.
Close cleans up the resources used by a TarReadCloser.
XzReader implements io.ReadCloser for data compressed via `xz`.
NewXzReader returns an io.ReadCloser by executing a command line `xz` executable to decompress the provided io.Reader.
It is the caller's responsibility to call Close on the XzReader when done.
Close cleans up the resources used by an XzReader.