Documentation
¶
Overview ¶
Package zip provides support for reading and writing ZIP archives.
See the ZIP specification for details.
This package does not support disk spanning.
A note about ZIP64:
To be backwards compatible the FileHeader has both 32 and 64 bit Size fields. The 64 bit fields will always contain the correct value and for normal archives both fields will be the same. For files requiring the ZIP64 format the 32 bit fields will be 0xffffffff and the 64 bit fields must be used instead.
Index ¶
Constants ¶
const ( Zip64ExtraID = 0x0001 // Zip64 extended information NtfsExtraID = 0x000a // NTFS UnixExtraID = 0x000d // UNIX ExtTimeExtraID = 0x5455 // Extended timestamp InfoZipUnixExtraID = 0x5855 // Info-ZIP Unix extension )
const ( CompressMethodStored = 0 CompressMethodDeflated = 8 )
const ( Store uint16 = 0 // no compression Deflate uint16 = 8 // DEFLATE compressed )
Compression methods.
Variables ¶
This section is empty.
Functions ¶
func MSDosTimeToTime ¶
Types ¶
type Entry ¶
type Entry struct {
zip.FileHeader
// contains filtered or unexported fields
}
type File ¶
type File struct {
FileHeader
// contains filtered or unexported fields
}
type FileHeader ¶
type FileHeader struct {
// Name is the name of the file.
//
// It must be a relative path, not start with a drive letter (such as "C:"),
// and must use forward slashes instead of back slashes. A trailing slash
// indicates that this file is a directory and should have no data.
Name string
// Comment is any arbitrary user-defined string shorter than 64KiB.
Comment string
// NonUTF8 indicates that Name and Comment are not encoded in UTF-8.
//
// By specification, the only other encoding permitted should be CP-437,
// but historically many ZIP readers interpret Name and Comment as whatever
// the system's local character encoding happens to be.
//
// This flag should only be set if the user intends to encode a non-portable
// ZIP file for a specific localized region. Otherwise, the Writer
// automatically sets the ZIP format's UTF-8 flag for valid UTF-8 strings.
NonUTF8 bool
CreatorVersion uint16
ReaderVersion uint16
Flags uint16
// Method is the compression method. If zero, Store is used.
Method uint16
// Modified is the modified time of the file.
//
// When reading, an extended timestamp is preferred over the legacy MS-DOS
// date field, and the offset between the times is used as the timezone.
// If only the MS-DOS date is present, the timezone is assumed to be UTC.
//
// When writing, an extended timestamp (which is timezone-agnostic) is
// always emitted. The legacy MS-DOS date field is encoded according to the
// location of the Modified time.
Modified time.Time
// ModifiedTime is an MS-DOS-encoded time.
//
// Deprecated: Use Modified instead.
ModifiedTime uint16
// ModifiedDate is an MS-DOS-encoded date.
//
// Deprecated: Use Modified instead.
ModifiedDate uint16
// CRC32 is the CRC32 checksum of the file content.
CRC32 uint32
// CompressedSize is the compressed size of the file in bytes.
// If either the uncompressed or compressed size of the file
// does not fit in 32 bits, CompressedSize is set to ^uint32(0).
//
// Deprecated: Use CompressedSize64 instead.
CompressedSize uint32
// UncompressedSize is the uncompressed size of the file in bytes.
// If either the uncompressed or compressed size of the file
// does not fit in 32 bits, UncompressedSize is set to ^uint32(0).
//
// Deprecated: Use UncompressedSize64 instead.
UncompressedSize uint32
// CompressedSize64 is the compressed size of the file in bytes.
CompressedSize64 uint64
// UncompressedSize64 is the uncompressed size of the file in bytes.
UncompressedSize64 uint64
Extra []byte
ExternalAttrs uint32 // Meaning depends on CreatorVersion
}
FileHeader describes a file within a ZIP file. See the ZIP specification for details.
func FileInfoHeader ¶
func FileInfoHeader(fi fs.FileInfo) (*FileHeader, error)
FileInfoHeader creates a partially-populated FileHeader from an fs.FileInfo. Because fs.FileInfo's Name method returns only the base name of the file it describes, it may be necessary to modify the Name field of the returned header to provide the full path name of the file. If compression is desired, callers should set the FileHeader.Method field; it is unset by default.
func (*FileHeader) FileInfo ¶
func (h *FileHeader) FileInfo() fs.FileInfo
FileInfo returns an fs.FileInfo for the FileHeader.
func (*FileHeader) ModTime
deprecated
func (h *FileHeader) ModTime() time.Time
ModTime returns the modification time in UTC using the legacy [ModifiedDate] and [ModifiedTime] fields.
Deprecated: Use [Modified] instead.
func (*FileHeader) Mode ¶
func (h *FileHeader) Mode() (mode fs.FileMode)
Mode returns the permission and mode bits for the FileHeader.
func (*FileHeader) SetModTime
deprecated
func (h *FileHeader) SetModTime(t time.Time)
SetModTime sets the [Modified], [ModifiedTime], and [ModifiedDate] fields to the given time in UTC.
Deprecated: Use [Modified] instead.
func (*FileHeader) SetMode ¶
func (h *FileHeader) SetMode(mode fs.FileMode)
SetMode changes the permission and mode bits for the FileHeader.