Documentation
¶
Index ¶
- Variables
- func CompressFiles(w io.Writer, format Format, files map[string]FileEntry) error
- func ExtractArchive(archiveData []byte, destDir string) error
- func ExtractBinary(archiveData []byte, binaryName string) ([]byte, error)
- func NewDecompressReader(r io.Reader, format Format) (io.Reader, error)
- type FileEntry
- type Format
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedFormat = fmt.Errorf("unsupported archive format") ErrFileNotFound = fmt.Errorf("file not found in archive") ErrInvalidData = fmt.Errorf("invalid archive data") )
Error definitions
Functions ¶
func CompressFiles ¶
CompressFiles creates an archive containing the given files map (filename -> FileEntry) and writes it to the destination io.Writer using the specified format.
func ExtractArchive ¶
ExtractArchive intelligently extracts all contents of an archive into the specified destination directory.
func ExtractBinary ¶
ExtractBinary intelligently extracts a named binary from various archive formats based on magic bytes. This is maintained for compatibility and ease of use in simple scenarios.
func NewDecompressReader ¶
NewDecompressReader creates an io.Reader that decompresses the given reader according to the format. If the format is not a compression stream (e.g. Zip or Raw), it returns the original reader unchanged.
Types ¶
type FileEntry ¶
type FileEntry struct {
Data []byte
Mode os.FileMode
ModTime time.Time
// Tar specific metadata
Uid int
Gid int
Uname string
Gname string
PAXRecords map[string]string // Custom key-value extensions
// Zip specific metadata
Comment string
}
FileEntry represents a file to be added to an archive.
type Format ¶
type Format string
Format represents an archive or compression format.
func DetectFormat ¶
DetectFormat attempts to detect the compression or archive format of the given data based on its magic bytes. If no known magic byte matches, it returns FormatRaw.
func (Format) IsCompression ¶
IsCompression returns true if the format is purely a compression stream (not a container like zip or tar).
func (Format) IsContainer ¶
IsContainer returns true if the format is an archive container (like zip or tar).