Documentation
¶
Index ¶
Constants ¶
const ( NoCompression = flate.NoCompression BestSpeed = flate.BestSpeed BestCompression = flate.BestCompression DefaultCompression = flate.DefaultCompression ConstantCompression = flate.ConstantCompression HuffmanOnly = flate.HuffmanOnly )
These constants are copied from the flate package, so that code that imports "compress/gzip" does not also have to import "compress/flate".
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeflateWriter ¶
type DeflateWriter struct {
// contains filtered or unexported fields
}
A DeflateWriter is an io.WriteCloser. Writes to a Writer are compressed and written to w.
func NewDeflateWriter ¶
func NewDeflateWriter(w io.Writer) *DeflateWriter
NewDeflateWriter returns a new Writer. Writes to the returned writer are compressed and written to w.
It is the caller's responsibility to call Close on the WriteCloser when done. Writes may be buffered and not flushed until Close.
Callers that wish to set the fields in Writer.Header must do so before the first call to Write or Close. The Comment and Name header fields are UTF-8 strings in Go, but the underlying format requires NUL-terminated ISO 8859-1 (Latin-1). NUL or non-Latin-1 runes in those strings will lead to an error on Write.
func NewDeflateWriterLevel ¶
func NewDeflateWriterLevel(w io.Writer, level int) (*DeflateWriter, error)
NewDeflateWriterLevel is like NewDeflateWriter but specifies the compression level instead of assuming DefaultCompression.
The compression level can be DefaultCompression, NoCompression, or any integer value between BestSpeed and BestCompression inclusive. The error returned will be nil if the level is valid.
func (*DeflateWriter) Close ¶
func (z *DeflateWriter) Close() error
Close closes the Writer, flushing any unwritten data to the underlying io.Writer, but does not close the underlying io.Writer.
func (*DeflateWriter) Flush ¶
func (z *DeflateWriter) Flush() error
Flush flushes any pending compressed data to the underlying writer.
It is useful mainly in compressed network protocols, to ensure that a remote reader has enough data to reconstruct a packet. Flush does not return until the data has been written. If the underlying writer returns an error, Flush returns that error.
In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH.
func (*DeflateWriter) Reset ¶
func (z *DeflateWriter) Reset(w io.Writer)
Reset discards the Writer z's state and makes it equivalent to the result of its original state from NewWriter or NewWriterLevel, but writing to w instead. This permits reusing a Writer rather than allocating a new one.
func (*DeflateWriter) SetConcurrency ¶
func (z *DeflateWriter) SetConcurrency(blockSize, blocks int) error
SetConcurrency finetunes the concurrency level if needed.
With this you can control the approximate size of your blocks, as well as how many you want to be processing in parallel.
Default values for this is SetConcurrency(defaultBlockSize, runtime.GOMAXPROCS(0)), meaning blocks are split at 1 MB and up to the number of CPU threads can be processing at once before the writer blocks.
func (*DeflateWriter) UncompressedSize ¶
func (z *DeflateWriter) UncompressedSize() int
UncompressedSize will return the number of bytes written. pgzip only, not a function in the official gzip package.
func (*DeflateWriter) Write ¶
func (z *DeflateWriter) Write(p []byte) (int, error)
Write writes a compressed form of p to the underlying io.Writer. The compressed bytes are not necessarily flushed to output until the Writer is closed or Flush() is called.
The function will return quickly, if there are unused buffers. The sent slice (p) is copied, and the caller is free to re-use the buffer when the function returns.
Errors that occur during compression will be reported later, and a nil error does not signify that the compression succeeded (since it is most likely still running) That means that the call that returns an error may not be the call that caused it. Only Flush and Close functions are guaranteed to return any errors up to that point.
type File ¶
type File struct { Name string UncompressedSize64 uint64 FileHeader zip.FileHeader Hash string // contains filtered or unexported fields }
File holds information about one file in a zip archive
type Reader ¶
type Reader struct { File []*File // contains filtered or unexported fields }
Reader defines the zip reader
func NewReader ¶
NewReader returns a new Reader reading from r, which is assumed to have the given size in bytes.
func (*Reader) GetFileByHash ¶
GetFileByHash gets the file by the hash value
type Writer ¶
Writer holds the data for writing to a zip archive, ignoring duplicate file names
func NewWriterLevel ¶
NewWriterLevel returns a new writer using the specified level
func (*Writer) CreateHeader ¶
CreateHeader creates a new header entry and returns a writer