Documentation ¶
Index ¶
- Constants
- type Reader
- type Resetter
- type Writer
- func NewWriter(w io.Writer) *Writer
- func NewWriterLevel(w io.Writer, level int) (*Writer, error)
- func NewWriterLevelDict(w io.Writer, level int, dict []byte) (*Writer, error)
- func NewWriterLevelStrategy(w io.Writer, level, strategy int) (*Writer, error)
- func NewWriterLevelStrategyDict(w io.Writer, level, strategy int, dict []byte) (*Writer, error)
Constants ¶
const ( //NoCompression does not compress given input NoCompression = 0 //BestSpeed is fastest but with lowest compression BestSpeed = 1 //BestCompression is slowest but with best compression BestCompression = 9 //DefaultCompression is a compromise between BestSpeed and BestCompression. //The level might change if algorithms change. DefaultCompression = -1 // Filtered is more effective for small (but not all too many) randomly distributed values. // It forces more Huffman encoding. Use it for filtered data. It's between Default and Huffman only. Filtered = 1 //HuffmanOnly only uses Huffman encoding to compress the given data HuffmanOnly = 2 //RLE (run-length encoding) limits match distance to one, thereby being almost as fast as HuffmanOnly // but giving better compression for PNG data. RLE = 3 //Fixed disallows dynamic Huffman codes, thereby making it a simpler decoder Fixed = 4 // DefaultStrategy is the default compression strategy that should be used for most appliances DefaultStrategy = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader decompresses data from an underlying io.Reader or via the ReadBuffer method, which should be preferred
func NewReader ¶
NewReader returns a new reader, reading from r. It decompresses read data. r may be nil if you only plan on using ReadBuffer
func NewReaderDict ¶
NewReaderDict does exactly like NewReader as of NOW. This will change once custom dicionaries are implemented. This function has been added for compatibility with the std lib.
func (*Reader) Close ¶
Close closes the Reader by closing and freeing the underlying zlib stream. You should not forget to call this after being done with the writer.
func (*Reader) Read ¶
Read reads compressed data from the underlying Reader into the provided buffer p. To reuse the reader after an EOF condition, you have to Reset it. Please consider using ReadBuffer for whole-buffered data instead, as it is faster and generally easier to use.
func (*Reader) ReadBuffer ¶ added in v1.1.0
ReadBuffer takes compressed data p, decompresses it to out in one go and returns out sliced accordingly. This method is generally faster than Read if you know the output size beforehand. If you don't, you can still try to use that method (provide out == nil) but that might take longer than Read. The method also returns the number n of bytes that were processed from the compressed slice. If n < len(compressed) and err == nil then only the first n compressed bytes were in a suitable zlib format and as such decompressed. ReadBuffer resets the reader for new decompression.
func (*Reader) Reset ¶
Reset resets the Reader to the state of being initialized with zlib.NewX(..), but with the new underlying reader instead. It allows for reuse of the same reader. AS OF NOW dict IS NOT USED. It's just there to implement the Resetter interface to allow for easy interchangeability with the std lib. Just pass nil.
type Resetter ¶
type Resetter interface { // Reset resets the Reader to the state of being initialized with zlib.NewX(..), // but with the new underlying reader and dict instead. It allows for reuse of the same reader. Reset(r io.Reader, dict []byte) error }
Resetter resets the zlib.Reader returned by NewReader by assigning a new underyling reader, discarding any buffered data from the previous reader. This interface is mainly for compatibility with the std lib
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer compresses and writes given data to an underlying io.Writer
func NewWriter ¶
NewWriter returns a new Writer with the underlying io.Writer to compress to. w may be nil if you only plan on using WriteBuffer. Panics if the underlying c stream cannot be allocated which would indicate a severe error not only for this library but also for the rest of your code.
func NewWriterLevel ¶
NewWriterLevel performs like NewWriter but you may also specify the compression level. w may be nil if you only plan on using WriteBuffer.
func NewWriterLevelDict ¶
NewWriterLevelDict does exactly like NewWriterLevel as of NOW. This will change once custom dicionaries are implemented. This function has been added for compatibility with the std lib.
func NewWriterLevelStrategy ¶
NewWriterLevelStrategy performs like NewWriter but you may also specify the compression level and strategy. w may be nil if you only plan on using WriteBuffer.
func NewWriterLevelStrategyDict ¶
NewWriterLevelStrategyDict does exactly like NewWriterLevelStrategy as of NOW. This will change once custom dicionaries are implemented. This function has been added mainly for completeness' sake.
func (*Writer) Close ¶
Close closes the writer by flushing any unwritten data to the underlying writer. You should not forget to call this after being done with the writer.
func (*Writer) Reset ¶
Reset flushes the buffered data to the current underyling writer, resets the Writer to the state of being initialized with zlib.NewX(..), but with the new underlying writer instead. This will panic if the writer has already been closed, writer could not be reset or could not write to current underlying writer.
func (*Writer) Write ¶
Write compresses the given data p and writes it to the underlying io.Writer. The data is not necessarily written to the underlying writer, if no Flush is called. It returns the number of *uncompressed* bytes written to the underlying io.Writer in case of err = nil, or the number of *compressed* bytes in case of err != nil. Please consider using WriteBuffer as it might be more convenient for your use case.
func (*Writer) WriteBuffer ¶ added in v1.1.0
WriteBuffer takes uncompressed data in, compresses it to out and returns out sliced accordingly. In most cases (if the compressed data is smaller than the uncompressed) an out buffer of size len(in) should be sufficient. If you pass nil for out, this function will try to allocate a fitting buffer. Use this for whole-buffered, in-memory data.