const (
Store uint16 = 0
Deflate uint16 = 8
)
Compression methods.
var (
ErrFormat = errors.New("zip: not a valid zip file")
ErrAlgorithm = errors.New("zip: unsupported compression algorithm")
ErrChecksum = errors.New("zip: checksum error")
)
type File struct {
FileHeader
// contains filtered or unexported fields
}
func (f *File) Open() (rc io.ReadCloser, err error)
Open returns a ReadCloser that provides access to the File's contents. Multiple files may be read concurrently.
type FileHeader struct {
// Name is the name of the file.
// It must be a relative path: it must not start with a drive
// letter (e.g. C:) or leading slash, and only forward slashes
// are allowed.
Name string
CreatorVersion uint16
ReaderVersion uint16
Flags uint16
Method uint16
ModifiedTime uint16 // MS-DOS time
ModifiedDate uint16 // MS-DOS date
CRC32 uint32
CompressedSize uint32 // deprecated; use CompressedSize64
UncompressedSize uint32 // deprecated; use UncompressedSize64
CompressedSize64 uint64
UncompressedSize64 uint64
Extra []byte
ExternalAttrs uint32 // Meaning depends on CreatorVersion
Comment string
}
FileHeader describes a file within a zip file. See the zip spec for details.
func FileInfoHeader(fi os.FileInfo) (*FileHeader, error)
FileInfoHeader creates a partially-populated FileHeader from an os.FileInfo.
func (h *FileHeader) FileInfo() os.FileInfo
FileInfo returns an os.FileInfo for the FileHeader.
func (h *FileHeader) ModTime() time.Time
ModTime returns the modification time. The resolution is 2s.
func (h *FileHeader) Mode() (mode os.FileMode)
Mode returns the permission and mode bits for the FileHeader.
func (h *FileHeader) SetModTime(t time.Time)
SetModTime sets the ModifiedTime and ModifiedDate fields to the given time. The resolution is 2s.
func (h *FileHeader) SetMode(mode os.FileMode)
SetMode changes the permission and mode bits for the FileHeader.
type ReadCloser struct {
Reader
// contains filtered or unexported fields
}
func OpenReader(name string) (*ReadCloser, error)
OpenReader will open the Zip file specified by name and return a ReadCloser.
func (rc *ReadCloser) Close() error
Close closes the Zip file, rendering it unusable for I/O.
type Reader struct {
File []*File
Comment string
// contains filtered or unexported fields
}
▹ Example
func NewReader(r io.ReaderAt, size int64) (*Reader, error)
NewReader returns a new Reader reading from r, which is assumed to have the given size in bytes.
type Writer struct {
// contains filtered or unexported fields
}
Writer implements a zip file writer.
▹ Example
func NewWriter(w io.Writer) *Writer
NewWriter returns a new Writer writing a zip file to w.
func (w *Writer) Close() error
Close finishes writing the zip file by writing the central directory. It does not (and can not) close the underlying writer.
func (w *Writer) Create(name string) (io.Writer, error)
Create adds a file to the zip file using the provided name. It returns a Writer to which the file contents should be written. The name must be a relative path: it must not start with a drive letter (e.g. C:) or leading slash, and only forward slashes are allowed. The file's contents must be written to the io.Writer before the next call to Create, CreateHeader, or Close.
func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)
CreateHeader adds a file to the zip file using the provided FileHeader for the file metadata. It returns a Writer to which the file contents should be written. The file's contents must be written to the io.Writer before the next call to Create, CreateHeader, or Close.