Documentation
¶
Index ¶
- Constants
- Variables
- func EncapsulateXCryptZip(finalPath, tempPath, password string) error
- 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 WithArchiverEncryptCD(enable bool) ArchiverOption
- func WithArchiverIncremental(b bool) ArchiverOption
- func WithArchiverLevel(level int) ArchiverOption
- func WithArchiverMethod(method uint16) ArchiverOption
- func WithArchiverOffset(n int64) ArchiverOption
- func WithArchiverPassword(password string) ArchiverOption
- func WithArchiverPathMapping(m map[string]string) ArchiverOption
- func WithArchiverPlatformMetadata(enable bool) ArchiverOption
- func WithArchiverRecovery(pct int, f interface{ ... }) ArchiverOption
- func WithArchiverSeekIndex(chunkSize uint32, continuous bool) ArchiverOption
- func WithArchiverSolid(b bool) ArchiverOption
- func WithArchiverTorrentZip(b bool) ArchiverOption
- func WithArchiverXattrs(b bool) ArchiverOption
- func WithStageDirectory(dir string) ArchiverOption
- type Compressor
- type Decompressor
- type Directory
- type Extractor
- type ExtractorOption
- func WithExtractorChownErrorHandler(fn func(name string, err error) error) ExtractorOption
- func WithExtractorConcurrency(n int) ExtractorOption
- func WithExtractorIncremental(b bool) ExtractorOption
- func WithExtractorKeepBroken(b bool) ExtractorOption
- func WithExtractorKeepNewerFiles(keep bool) ExtractorOption
- func WithExtractorKeepOldFiles(keep bool) ExtractorOption
- func WithExtractorMaxFileSize(n int64) ExtractorOption
- func WithExtractorMaxRatio(n int64) ExtractorOption
- func WithExtractorNoTimes(noTimes bool) ExtractorOption
- func WithExtractorNumericOwner(b bool) ExtractorOption
- func WithExtractorPassword(password string) ExtractorOption
- func WithExtractorSafeWrites(b bool) ExtractorOption
- func WithExtractorSparse(b bool) ExtractorOption
- func WithExtractorStripComponents(count int) ExtractorOption
- func WithExtractorTolerant(b bool) ExtractorOption
- func WithExtractorUnlinkFirst(b bool) ExtractorOption
- func WithExtractorXattrs(b bool) ExtractorOption
- type File
- type FileHeader
- func (h *FileHeader) FileInfo() fs.FileInfo
- func (h *FileHeader) IsEncrypted() bool
- func (h *FileHeader) ModTime() time.Time
- func (h *FileHeader) Mode() (mode fs.FileMode)
- func (h *FileHeader) SetComment(comment string)
- func (h *FileHeader) SetModTime(t time.Time)
- func (h *FileHeader) SetMode(mode fs.FileMode)
- type MultiVolumeReader
- type MultiVolumeWriter
- 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)
- func (w *Writer) SetTorrentZip(b bool)
- type XCryptHeader
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.
const MappedStringMark = '\uFFFE'
const MappedStringMarkStr = "\uFFFE"
Variables ¶
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 = true
ConfigIncludePlatformMetadata defines if FileInfoHeader should automatically include OS-specific metadata (like UID/GID on Unix). Enabled by default to match system archivers behavior.
var DisableInsecurePaths bool
DisableInsecurePaths controls whether paths containing ".." or "\" are rejected.
var ErrArchiveLocked = errors.New("zip: cannot modify archive, it is locked")
var ErrMinConcurrency = errors.New("concurrency must be at least 1")
var MaxDecompressionDictSize int64 = 128 << 20
MaxDecompressionDictSize defines the maximum dictionary memory allocation (in bytes) allowed for PPMd and LZMA decompilers to prevent RAM bomb DoS attacks. Defaults to 128 MB.
Functions ¶
func EncapsulateXCryptZip ¶ added in v0.1.50
EncapsulateXCryptZip is a public wrapper to allow the archiver component to call the internal encapsulateXCryptZip function.
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 ¶
func (*Archiver) SetComment ¶ added in v0.1.30
SetComment sets the global archive comment in the Central Directory.
type ArchiverOption ¶
type ArchiverOption func(*archiverOptions) error
func WithArchiverBufferSize ¶
func WithArchiverBufferSize(n int) ArchiverOption
func WithArchiverConcurrency ¶
func WithArchiverConcurrency(n int) ArchiverOption
func WithArchiverEncryptCD ¶ added in v0.1.22
func WithArchiverEncryptCD(enable bool) ArchiverOption
WithArchiverEncryptCD enables Central Directory Encryption (CDE).
func WithArchiverIncremental ¶ added in v0.1.14
func WithArchiverIncremental(b bool) ArchiverOption
WithArchiverIncremental includes a .zip_dumpdir index of all active files for incremental restore.
func WithArchiverLevel ¶ added in v0.1.36
func WithArchiverLevel(level int) ArchiverOption
WithArchiverLevel sets the compression level (1-9 for Deflate, 1-4 for ZSTD).
func WithArchiverMethod ¶
func WithArchiverMethod(method uint16) ArchiverOption
func WithArchiverOffset ¶
func WithArchiverOffset(n int64) ArchiverOption
func WithArchiverPassword ¶ added in v0.1.22
func WithArchiverPassword(password string) ArchiverOption
WithArchiverPassword sets the password for WinZip AES encryption.
func WithArchiverPathMapping ¶ added in v0.1.56
func WithArchiverPathMapping(m map[string]string) ArchiverOption
WithArchiverPathMapping sets the path mapping for logical names in the archive.
func WithArchiverPlatformMetadata ¶
func WithArchiverPlatformMetadata(enable bool) ArchiverOption
WithArchiverPlatformMetadata enables inclusion of local OS metadata (UID/GID) for this archiver instance.
func WithArchiverRecovery ¶ added in v0.1.26
func WithArchiverRecovery(pct int, f interface{ Name() string }) ArchiverOption
WithArchiverRecovery устанавливает параметры PAR2 избыточности
func WithArchiverSeekIndex ¶ added in v0.1.17
func WithArchiverSeekIndex(chunkSize uint32, continuous bool) ArchiverOption
WithArchiverSeekIndex enables generation of a Seek Index for large files or solid archives.
func WithArchiverSolid ¶ added in v0.1.14
func WithArchiverSolid(b bool) ArchiverOption
WithArchiverSolid enables solid ZIP-in-ZIP packaging to achieve maximum compression ratio.
func WithArchiverTorrentZip ¶ added in v0.1.25
func WithArchiverTorrentZip(b bool) ArchiverOption
func WithArchiverXattrs ¶ added in v0.1.8
func WithArchiverXattrs(b bool) ArchiverOption
WithArchiverXattrs enables archiving of extended attributes (xattrs, POSIX ACLs, SELinux).
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 WithExtractorIncremental ¶ added in v0.1.14
func WithExtractorIncremental(b bool) ExtractorOption
WithExtractorIncremental enables processing of .zip_dumpdir headers to remove deleted files during incremental restores.
func WithExtractorKeepBroken ¶ added in v0.1.11
func WithExtractorKeepBroken(b bool) ExtractorOption
func WithExtractorKeepNewerFiles ¶ added in v0.1.13
func WithExtractorKeepNewerFiles(keep bool) ExtractorOption
WithExtractorKeepNewerFiles prevents overwriting files that are newer on disk (--keep-newer-files)
func WithExtractorKeepOldFiles ¶ added in v0.1.13
func WithExtractorKeepOldFiles(keep bool) ExtractorOption
WithExtractorKeepOldFiles prevents overwriting existing files (-k or --keep-old-files)
func WithExtractorMaxFileSize ¶
func WithExtractorMaxFileSize(n int64) ExtractorOption
func WithExtractorMaxRatio ¶
func WithExtractorMaxRatio(n int64) ExtractorOption
func WithExtractorNoTimes ¶ added in v0.1.13
func WithExtractorNoTimes(noTimes bool) ExtractorOption
WithExtractorNoTimes prevents restoring original modification times (-m / --touch)
func WithExtractorNumericOwner ¶ added in v0.1.14
func WithExtractorNumericOwner(b bool) ExtractorOption
WithExtractorNumericOwner always uses numeric user/group IDs from the archive rather than resolving Uname/Gname (--numeric-owner).
func WithExtractorPassword ¶ added in v0.1.22
func WithExtractorPassword(password string) ExtractorOption
WithExtractorPassword sets the password for WinZip AES and CDE decryption.
func WithExtractorSafeWrites ¶ added in v0.1.13
func WithExtractorSafeWrites(b bool) ExtractorOption
WithExtractorSafeWrites extracts files atomically by writing to a temporary file and renaming (--safe-writes).
func WithExtractorSparse ¶ added in v0.1.13
func WithExtractorSparse(b bool) ExtractorOption
WithExtractorSparse enables extracting files as sparse files by seeking over zero-blocks (-S, --sparse).
func WithExtractorStripComponents ¶ added in v0.1.13
func WithExtractorStripComponents(count int) ExtractorOption
WithExtractorStripComponents strips the specified number of leading components from file names on extraction (--strip-components)
func WithExtractorTolerant ¶ added in v0.1.15
func WithExtractorTolerant(b bool) ExtractorOption
WithExtractorTolerant allows extraction to continue even if some files are corrupted.
func WithExtractorUnlinkFirst ¶ added in v0.1.13
func WithExtractorUnlinkFirst(b bool) ExtractorOption
WithExtractorUnlinkFirst removes existing files prior to extracting over them (-U, --unlink-first).
func WithExtractorXattrs ¶ added in v0.1.8
func WithExtractorXattrs(b bool) ExtractorOption
WithExtractorXattrs enables restoration of extended attributes (xattrs, POSIX ACLs, SELinux).
type File ¶
type File struct {
FileHeader
// contains filtered or unexported fields
}
func (*File) DataOffset ¶
func (*File) HeaderOffset ¶ added in v0.1.109
func (*File) OpenSeekable ¶ added in v0.1.17
func (f *File) OpenSeekable() (io.ReadSeeker, error)
OpenSeekable returns a ReadSeeker for the file content. It requires a Seek Index (Hidden SOZip or GZIDX) to be present in the archive for compressed files.
type FileHeader ¶
type FileHeader struct {
Name string
Comment string
NonUTF8 bool // If set, disables automatic UTF-8 flag encoding
RecoveryPct int // Уровень избыточности PAR2 для всего архива
RecoveryFile *os.File
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
Uname string // User name of owner
Gname string // Group name of owner
// Hardlinks & Devices
Devmajor int64
Devminor int64
Linkname string
// Xattrs
Xattrs map[string]string
// NTFS Attributes
Acl []byte // Windows Security Descriptor (ACL)
// Seek Index (SOZip / GZIDX Hidden files)
SeekChunkSize uint32 // Uncompressed block size (e.g. 1MB)
SeekIndex []uint64 // SOZip compressed offsets
GzidxPoints []gzPoint // GZIDX stateful points
SeekContinuous bool // If true, generate GZIDX instead of SOZip
// WinZip AES encryption
Password string
AESStrength byte // 1 = 128, 2 = 192, 3 = 256. Defaults to 3 (AES-256) if Password != ""
Level int
}
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) SetComment ¶ added in v0.1.29
func (h *FileHeader) SetComment(comment string)
func (*FileHeader) SetModTime ¶
func (h *FileHeader) SetModTime(t time.Time)
func (*FileHeader) SetMode ¶
func (h *FileHeader) SetMode(mode fs.FileMode)
type MultiVolumeReader ¶ added in v0.1.27
type MultiVolumeReader struct {
// contains filtered or unexported fields
}
MultiVolumeReader joins multiple files into a single virtual ReaderAt/WriterAt stream.
func OpenMultiVolume ¶ added in v0.1.27
func OpenMultiVolume(mainPath string, flag int) (*MultiVolumeReader, int64, error)
OpenMultiVolume looks for archive parts (.z01, .z02...) alongside the .zip file
func (*MultiVolumeReader) Append ¶ added in v0.1.27
func (m *MultiVolumeReader) Append(data []byte) error
func (*MultiVolumeReader) Close ¶ added in v0.1.27
func (m *MultiVolumeReader) Close() error
type MultiVolumeWriter ¶ added in v0.1.27
type MultiVolumeWriter struct {
// contains filtered or unexported fields
}
MultiVolumeWriter transparently splits data across multiple files.
func NewMultiVolumeWriter ¶ added in v0.1.27
func NewMultiVolumeWriter(mainPath string, splitSize int64) (*MultiVolumeWriter, error)
func (*MultiVolumeWriter) Close ¶ added in v0.1.27
func (m *MultiVolumeWriter) Close() error
func (*MultiVolumeWriter) Name ¶ added in v0.1.27
func (m *MultiVolumeWriter) Name() string
func (*MultiVolumeWriter) Sync ¶ added in v0.1.27
func (m *MultiVolumeWriter) Sync() error
type ReadCloser ¶
type ReadCloser struct {
Reader
// contains filtered or unexported fields
}
func OpenReader ¶
func OpenReader(name string) (*ReadCloser, error)
func OpenReaderWithPassword ¶ added in v0.1.22
func OpenReaderWithPassword(name string, password string) (*ReadCloser, error)
func (*ReadCloser) Close ¶
func (rc *ReadCloser) Close() error
type Reader ¶
func NewReaderWithPassword ¶ added in v0.1.22
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.
WARNING: In-place updates modify the underlying file directly. If the process crashes, is killed, or encounters a power failure during an operation (especially APPEND_MODE_OVERWRITE or RemoveFile), the archive may be left in a corrupted and unrecoverable state. For mission-critical data, it is recommended to backup the archive before updating.
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.
func (*Writer) SetTorrentZip ¶ added in v0.1.25
SetTorrentZip enables torrentzip compatibility mode. It enforces predictable timestamps, clears extra fields, disables data descriptors, and appends a TORRENTZIPPED- CRC32 comment to the archive.
type XCryptHeader ¶ added in v0.1.50
type XCryptHeader struct {
Version uint8
KdfAlgo uint8
Cipher uint8
Iterations uint32
Salt []byte
IV []byte
MAC []byte
}
F4CryptHeader represents the 93-byte binary header for encrypted streams
func (*XCryptHeader) DeriveKey ¶ added in v0.1.50
func (h *XCryptHeader) DeriveKey(password string) []byte
func (*XCryptHeader) Encode ¶ added in v0.1.50
func (h *XCryptHeader) Encode() []byte
Source Files
¶
- aes.go
- archiver.go
- crypto.go
- deflate64.go
- deflate64_enc_const.go
- deflate64_huffman.go
- deflate64_match.go
- deflate64_optimal.go
- deflate64_writer.go
- extra_ntfs.go
- extra_unix.go
- extractor.go
- fs_linux.go
- fs_unix.go
- motw.go
- multivolume.go
- os_wrapper.go
- pua.go
- reader.go
- recovery.go
- register.go
- struct.go
- sys_linux.go
- sys_unix.go
- tar.go
- updater.go
- writer.go
- zipcrypto.go