Documentation ¶
Overview ¶
Package pkzip provides constants and functions for working with PKZip files to determine the compression methods used. Most modern zip files use the Deflated method, which is supported by the Go standard library's archive/zip package and the Stored method, which is uncompressed.
But many older zip files use other compression methods, such as Shrunk, Reduced, Imploded, and others. This package provides a way to determine the compression methods used in a zip file and whether the file should be handled by a third-party application installed on the host system.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Compression ¶
type Compression uint16
Compression is the PKZip compression method used by a ZIP archive file.
const ( Stored Compression = iota Shrunk ReducedFactor1 ReducedFactor2 ReducedFactor3 ReducedFactor4 Imploded Reserved Deflated EnhancedDeflated PKWareDataCompressionLibraryImplode BZIP2 Reserved2 LZMA Reserved3 Reserved4 IBMTERSE IBMLZ77z )
const (
PPMd1 Compression = iota + 98
)
func Methods ¶
func Methods(name string) ([]Compression, error)
Methods returns the PKZip compression methods used in the named file.
func (Compression) String ¶
func (c Compression) String() string
func (Compression) Zip ¶
func (c Compression) Zip() bool
Zip returns true if the compression method is Deflated or Stored.
type Diagnostic ¶
type Diagnostic uint16
Diagnostic is a diagnostic code returned by the PKZip command-line utilities.
const ( Normal Diagnostic = iota Warning GenericError SevereError BufferError TTYError DiskError MemoryError Unused ZipNotFound OptionsError FilesNoFound ZipBomb )
const ( DiskFull Diagnostic = 50 PrematureExit Diagnostic = 51 UserAbort Diagnostic = 80 CompressionMethod Diagnostic = 81 BadDecryption Diagnostic = 82 )
func ExitStatus ¶
func ExitStatus(err error) Diagnostic
ExitStatus is intended to be used with the exec.Command.Run method to determine the exit status of the PKZip command-line utilities.
err := exec.Command("unzip", "-T", "archive.zip").Run() if err != nil { diag := pkzip.ExitStatus(err) switch diag { case pkzip.Normal, pkzip.Warning: // normal or warnings are fine return nil } return fmt.Errorf("unzip test failed: %s", diag) }
func (Diagnostic) String ¶
func (d Diagnostic) String() string