Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterCompressor(method uint16, comp Compressor)
- func RegisterDecompressor(method uint16, dcomp Decompressor)
- type AppendMode
- type Archiver
- type ArchiverOption
- func WithArchiverBufferSize(n int) ArchiverOption
- func WithArchiverConcurrency(n int) ArchiverOption
- func WithArchiverMethod(method uint16) ArchiverOption
- func WithArchiverOffset(n int64) ArchiverOption
- func WithArchiverPlatformMetadata(enable bool) ArchiverOption
- func WithStageDirectory(dir string) ArchiverOption
- type Compressor
- type Decompressor
- type Directory
- type Extractor
- type ExtractorOption
- type File
- type FileHeader
- type ReadCloser
- type Reader
- type Updater
- func (u *Updater) Append(name string, mode AppendMode) (io.Writer, error)
- func (u *Updater) AppendHeader(fh *FileHeader, mode AppendMode) (io.Writer, error)
- func (u *Updater) Close() error
- func (u *Updater) Entries() []*FileHeader
- func (u *Updater) GetComment() string
- func (u *Updater) RemoveFile(dirIndex int) (int64, error)
- func (u *Updater) SetComment(comment string) error
- type Writer
- func (w *Writer) AddFS(fsys fs.FS) error
- func (w *Writer) Close() error
- func (w *Writer) Copy(f *File) error
- func (w *Writer) Create(name string) (io.Writer, error)
- func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)
- func (w *Writer) CreateRaw(fh *FileHeader) (io.Writer, error)
- func (w *Writer) Flush() error
- func (w *Writer) RegisterCompressor(method uint16, comp Compressor)
- func (w *Writer) SetComment(comment string) error
- func (w *Writer) SetEncryptCentralDirectory(enable bool, password string)
- func (w *Writer) SetOffset(n int64)
Constants ¶
const ( Store uint16 = 0 // no compression Deflate uint16 = 8 // DEFLATE compressed Deflate64 uint16 = 9 BZIP2 uint16 = 12 LZMA uint16 = 14 ZSTD uint16 = 93 // Zstandard compressed )
Compression methods.
Variables ¶
var ( OEMDecoder *encoding.Decoder = charmap.CodePage437.NewDecoder() ANSIDecoder *encoding.Decoder = charmap.Windows1252.NewDecoder() SystemDecoder *encoding.Decoder = charmap.CodePage437.NewDecoder() )
Legacy Decoders configuration. They are automatically initialized based on the system locale during init(). You can override them manually if you need strict enforcement.
var ( ErrFormat = errors.New("zip: not a valid zip file") ErrAlgorithm = errors.New("zip: unsupported compression algorithm") ErrChecksum = errors.New("zip: checksum error") ErrInsecurePath = errors.New("zip: insecure file path") )
var ConfigIncludePlatformMetadata = false
ConfigIncludePlatformMetadata defines if FileInfoHeader should automatically include OS-specific metadata (like UID/GID on Unix). Disabled by default to ensure archive portability.
var ErrMinConcurrency = errors.New("concurrency must be at least 1")
Functions ¶
func RegisterCompressor ¶
func RegisterCompressor(method uint16, comp Compressor)
func RegisterDecompressor ¶
func RegisterDecompressor(method uint16, dcomp Decompressor)
Types ¶
type AppendMode ¶
type AppendMode int
AppendMode specifies the way to append new file to existing zip archive.
const ( // APPEND_MODE_OVERWRITE removes the existing file data and append the new // data to the end of the zip archive. APPEND_MODE_OVERWRITE AppendMode = iota // APPEND_MODE_KEEP_ORIGINAL will keep the original file data and only // write the new file data at the end of the existing zip archive file. // This mode will keep multiple file with same name into one archive file. APPEND_MODE_KEEP_ORIGINAL )
type Archiver ¶
type Archiver struct {
// contains filtered or unexported fields
}
func NewArchiver ¶
type ArchiverOption ¶
type ArchiverOption func(*archiverOptions) error
func WithArchiverBufferSize ¶
func WithArchiverBufferSize(n int) ArchiverOption
func WithArchiverConcurrency ¶
func WithArchiverConcurrency(n int) ArchiverOption
func WithArchiverMethod ¶
func WithArchiverMethod(method uint16) ArchiverOption
func WithArchiverOffset ¶
func WithArchiverOffset(n int64) ArchiverOption
func WithArchiverPlatformMetadata ¶
func WithArchiverPlatformMetadata(enable bool) ArchiverOption
WithArchiverPlatformMetadata enables inclusion of local OS metadata (UID/GID) for this archiver instance.
func WithStageDirectory ¶
func WithStageDirectory(dir string) ArchiverOption
type Compressor ¶
type Compressor func(w io.Writer) (io.WriteCloser, error)
type Decompressor ¶
type Decompressor func(r io.Reader) io.ReadCloser
type Directory ¶
type Directory struct {
FileHeader
// contains filtered or unexported fields
}
func (*Directory) HeaderOffset ¶
type Extractor ¶
type Extractor struct {
// contains filtered or unexported fields
}
func NewExtractor ¶
func NewExtractor(filename, chroot string, opts ...ExtractorOption) (*Extractor, error)
func NewExtractorFromReader ¶
type ExtractorOption ¶
type ExtractorOption func(*extractorOptions) error
func WithExtractorChownErrorHandler ¶
func WithExtractorChownErrorHandler(fn func(name string, err error) error) ExtractorOption
func WithExtractorConcurrency ¶
func WithExtractorConcurrency(n int) ExtractorOption
func WithExtractorMaxFileSize ¶
func WithExtractorMaxFileSize(n int64) ExtractorOption
func WithExtractorMaxRatio ¶
func WithExtractorMaxRatio(n int64) ExtractorOption
type File ¶
type File struct {
FileHeader
// contains filtered or unexported fields
}
func (*File) DataOffset ¶
type FileHeader ¶
type FileHeader struct {
Name string
Comment string
NonUTF8 bool // If set, disables automatic UTF-8 flag encoding
CreatorVersion uint16
ReaderVersion uint16
Flags uint16
Method uint16
Modified time.Time
Accessed time.Time
Created time.Time
ModifiedTime uint16 // Deprecated
ModifiedDate uint16 // Deprecated
CRC32 uint32
CompressedSize uint32 // Deprecated: Use CompressedSize64
UncompressedSize uint32 // Deprecated: Use UncompressedSize64
CompressedSize64 uint64
UncompressedSize64 uint64
Extra []byte
ExternalAttrs uint32
// UNIX attributes
Uid int
Gid int
OwnerSet bool
// NTFS Attributes
Acl []byte // Windows Security Descriptor (ACL)
// WinZip AES encryption
Password string
AESStrength byte // 1 = 128, 2 = 192, 3 = 256. Defaults to 3 (AES-256) if Password != ""
}
FileHeader describes a file within a ZIP file.
func FileInfoHeader ¶
func FileInfoHeader(fi fs.FileInfo) (*FileHeader, error)
func (*FileHeader) FileInfo ¶
func (h *FileHeader) FileInfo() fs.FileInfo
func (*FileHeader) IsEncrypted ¶
func (h *FileHeader) IsEncrypted() bool
func (*FileHeader) ModTime ¶
func (h *FileHeader) ModTime() time.Time
func (*FileHeader) Mode ¶
func (h *FileHeader) Mode() (mode fs.FileMode)
func (*FileHeader) SetModTime ¶
func (h *FileHeader) SetModTime(t time.Time)
func (*FileHeader) SetMode ¶
func (h *FileHeader) SetMode(mode fs.FileMode)
type ReadCloser ¶
type ReadCloser struct {
Reader
// contains filtered or unexported fields
}
func OpenReader ¶
func OpenReader(name string) (*ReadCloser, error)
func (*ReadCloser) Close ¶
func (rc *ReadCloser) Close() error
type Reader ¶
func (*Reader) RegisterDecompressor ¶
func (r *Reader) RegisterDecompressor(method uint16, dcomp Decompressor)
func (*Reader) SetPassword ¶
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater allows to modify & append files into an existing zip archive without decompress the whole file.
func NewUpdater ¶
func NewUpdater(rws io.ReadWriteSeeker) (*Updater, error)
NewUpdater returns a new Updater from io.ReadWriteSeeker, which is assumed to have the given size in bytes.
func (*Updater) AppendHeader ¶
func (u *Updater) AppendHeader(fh *FileHeader, mode AppendMode) (io.Writer, error)
func (*Updater) Entries ¶
func (u *Updater) Entries() []*FileHeader
func (*Updater) GetComment ¶
func (*Updater) SetComment ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func (*Writer) CreateHeader ¶
func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)
func (*Writer) RegisterCompressor ¶
func (w *Writer) RegisterCompressor(method uint16, comp Compressor)
func (*Writer) SetComment ¶
func (*Writer) SetEncryptCentralDirectory ¶
SetEncryptCentralDirectory enables encryption of the central directory records. This hides file names and metadata from unauthorized users. Requires a password to be set.