Documentation ¶
Index ¶
- type BlockEvent
- type BlockType
- type Checksum32
- type CompressLevel
- type CorruptInputError
- type DataType
- type Event
- type EventType
- type ExtraData
- type ExtraDataRecord
- type FlushType
- type FooterEvent
- type Format
- type Header
- type MemoryLevel
- type Method
- type NoOpTracer
- type OSType
- type Option
- func WithCompressLevel(clevel CompressLevel) Option
- func WithDictionary(dict []byte) Option
- func WithFormat(format Format) Option
- func WithMemoryLevel(mlevel MemoryLevel) Option
- func WithMethod(method Method) Option
- func WithStrategy(strategy Strategy) Option
- func WithTracers(tracers ...Tracer) Option
- func WithWindowBits(wbits WindowBits) Option
- type Reader
- func (fr *Reader) Close() error
- func (fr *Reader) Dict() []byte
- func (fr *Reader) Format() Format
- func (fr *Reader) MemoryLevel() MemoryLevel
- func (fr *Reader) Read(p []byte) (int, error)
- func (fr *Reader) Reset(r io.Reader, opts ...Option)
- func (fr *Reader) Tracers() []Tracer
- func (fr *Reader) UnderlyingReader() io.Reader
- func (fr *Reader) WindowBits() WindowBits
- type SizeList
- type Strategy
- type Tracer
- type TracerFunc
- type TreesEvent
- type WindowBits
- type Writer
- func (fw *Writer) Close() error
- func (fw *Writer) CompressLevel() CompressLevel
- func (fw *Writer) Dict() []byte
- func (fw *Writer) Flush(flushType FlushType) error
- func (fw *Writer) Format() Format
- func (fw *Writer) MemoryLevel() MemoryLevel
- func (fw *Writer) Method() Method
- func (fw *Writer) Reset(w io.Writer, opts ...Option)
- func (fw *Writer) SetHeader(header Header) error
- func (fw *Writer) Strategy() Strategy
- func (fw *Writer) Tracers() []Tracer
- func (fw *Writer) UnderlyingWriter() io.Writer
- func (fw *Writer) WindowBits() WindowBits
- func (fw *Writer) Write(buf []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockEvent ¶
BlockEvent is a sub-struct that is only present for BlockFooEvent.
type BlockType ¶
type BlockType byte
BlockType indicates the type of a DEFLATE-compressed block.
const ( // InvalidBlock is a dummy value indicating an invalid block. InvalidBlock BlockType = iota // StoredBlock indicates a stored (uncompressed) block. StoredBlock // StaticBlock indicates a Huffman-compressed block that uses the // static (pre-defined) Huffman encoding. StaticBlock // DynamicBlock indicates a Huffman-compressed block that uses a // dynamic Huffman encoding produced just for this block. DynamicBlock )
func (BlockType) GoString ¶
GoString returns the Go string representation of this BlockType constant.
func (BlockType) MarshalJSON ¶
MarshalJSON returns the JSON representation of this BlockType constant.
type Checksum32 ¶
type Checksum32 uint32
Checksum32 is a lightweight wrapper around uint32 that is used for 32-bit checksums, such as CRC-32 or Adler-32. It stringifies to hexadecimal format.
func (Checksum32) GoString ¶
func (csum Checksum32) GoString() string
GoString returns the Go string representation of this Checksum32 value.
func (Checksum32) MarshalJSON ¶
func (csum Checksum32) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON representation of this Checksum32 value.
func (Checksum32) String ¶
func (csum Checksum32) String() string
String returns the string representation of this Checksum32 value.
func (*Checksum32) UnmarshalJSON ¶
func (csum *Checksum32) UnmarshalJSON(raw []byte) error
UnmarshalJSON parses the JSON representation of a Checksum32 value.
type CompressLevel ¶
type CompressLevel int8
CompressLevel indicates the desired effort / CPU time to expend in finding an optimal compression stream.
const ( // DefaultCompression requests that the default value for CompressLevel // be selected. This is currently equivalent to 6. DefaultCompression CompressLevel = -1 // NoCompression requests that the data be stored literally, rather // than compressed. NoCompression CompressLevel = 0 // FastestCompression requests that the data be compressed with the // greatest speed and least effort. FastestCompression CompressLevel = 1 // BestCompression requests that the data be compressed with the // greatest effort and least speed. BestCompression CompressLevel = 9 )
func (CompressLevel) GoString ¶
func (clevel CompressLevel) GoString() string
GoString returns the Go string representation of this CompressLevel constant.
func (CompressLevel) IsValid ¶
func (clevel CompressLevel) IsValid() bool
IsValid returns true if clevel is a valid CompressLevel constant.
func (CompressLevel) MarshalJSON ¶
func (clevel CompressLevel) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON representation of this CompressLevel constant.
func (*CompressLevel) Parse ¶
func (clevel *CompressLevel) Parse(str string) error
Parse parses a string representation of a CompressLevel constant.
func (CompressLevel) String ¶
func (clevel CompressLevel) String() string
String returns the string representation of this CompressLevel constant.
type CorruptInputError ¶
CorruptInputError is returned when the stream being decompressed contains data that violates the compression format standard.
func (CorruptInputError) Error ¶
func (err CorruptInputError) Error() string
Error fulfills the error interface.
type DataType ¶
type DataType byte
DataType indicates the autodetected content type of the compressed data, text (ASCII-compatible, including ISO-8859-1 or UTF-8) vs binary (anything else).
func (DataType) MarshalJSON ¶
MarshalJSON returns the JSON representation of this DataType constant.
type Event ¶
type Event struct { Type EventType InputBytesTotal uint64 InputBytesStream uint64 OutputBytesTotal uint64 OutputBytesStream uint64 NumStreams uint Format Format Header *Header Block *BlockEvent Trees *TreesEvent }
Event is a collection of fields that provide feedback on the progress of the compression or decompression operation in progress. Events are provided to Tracers registered with a Reader or Writer.
type EventType ¶
type EventType byte
EventType indicates the type of an Event.
const ( // StreamBeginEvent indicates that the beginning of a compressed stream // was detected. StreamBeginEvent EventType = iota // StreamHeaderEvent indicates that the stream header was successfully // processed. StreamHeaderEvent // BlockBeginEvent indicates that a block was detected. BlockBeginEvent // BlockTreesEvent indicates that the Huffman tree metadata for the // current block have been successfully processed. BlockTreesEvent // BlockEndEvent indicates that the data for the current block has been // successfully processed. BlockEndEvent // StreamEndEvent indicates that the end of the current stream was // detected. StreamEndEvent // StreamCloseEvent indicates that the stream footer was successfully // processed. StreamCloseEvent )
func (EventType) GoString ¶
GoString returns the Go string representation of this EventType constant.
func (EventType) MarshalJSON ¶
MarshalJSON returns the JSON representation of this EventType constant.
type ExtraData ¶
type ExtraData struct {
Records []ExtraDataRecord
}
ExtraData represents a collection of records in a gzip ExtraData header.
type ExtraDataRecord ¶
ExtraDataRecord represents a single record in a gzip ExtraData header.
type FlushType ¶
type FlushType byte
FlushType indicates which type of Flush() operation is to be performed.
const ( // BlockFlush completes the current block. Some bits of the current // block may remain un-flushed in memory after this Flush(). // // BlockFlush can impact your compression ratio by forcing the // premature end of the current block. // BlockFlush FlushType = iota // PartialFlush completes the current block and writes an empty // static-tree Huffman block (10 bits) as padding. As the empty block // is more than 8 bits, all bits of the current block are guaranteed to // reach the underlying io.Writer by the completion of this Flush(). // // Like BlockFlush, PartialFlush can impact your compression ratio. // PartialFlush // SyncFlush completes the current block and writes an empty // uncompressed block (35+ bits). In addition to the guarantees made // by PartialFlush, this also guarantees that the next block will start // on a byte boundary. // // Like BlockFlush, SyncFlush can impact your compression ratio. // SyncFlush // FullFlush completes the current block, writes an empty uncompressed // block (35+ bits), and forgets the current sliding window. In // addition to the guarantees made by PartialFlush and SyncFlush, this // also allows the stream reader to begin decompression at the start of // the next block without looking at any previous data. // // FullFlush will seriously degrade your compression ratio if not used // wisely, far more than BlockFlush would. // FullFlush // FinishFlush completes the current block, writes an empty // uncompressed block (35+ bits) that is marked BFINAL=1, writes the // footers for the current file format (if any), and forgets the // current sliding window. // // Any data written after this will begin a new concatenated stream. // Most users will want to call Close() instead. FinishFlush )
func (FlushType) GoString ¶
GoString returns the Go string representation of this FlushType constant.
func (FlushType) MarshalJSON ¶
MarshalJSON returns the JSON representation of this FlushType constant.
type FooterEvent ¶
type FooterEvent struct {}
FooterEvent is a sub-struct that is only present for StreamEndEvent.
type Format ¶
type Format byte
Format indicates the file format to be written (Writer) or expected to be read (Reader).
const ( // DefaultFormat requests that Reader autodetect the file format, and // requests that Writer use the default format (currently ZlibFormat). DefaultFormat Format = iota // RawFormat indicates that a raw DEFLATE stream is in use, with no // headers or footers. RawFormat // ZlibFormat indicates that a zlib stream (RFC 1950) is in use. ZlibFormat // GZIPFormat indicates that a gzip stream (RFC 1952) is in use. GZIPFormat )
func (Format) MarshalJSON ¶
MarshalJSON returns the JSON representation of this Format constant.
type Header ¶
type Header struct { FileName string Comment string LastModified time.Time DataType DataType OSType OSType ExtraData ExtraData WindowBits WindowBits CompressLevel CompressLevel }
Header is a collection of fields which may be present in the headers of a gzip or zlib stream.
type MemoryLevel ¶
type MemoryLevel byte
MemoryLevel indicates the amount of RAM for the Reader or Writer to use.
const ( // DefaultMemory requests that the default value for MemoryLevel be // selected. This is currently equivalent to 9 (FastestMemory). DefaultMemory MemoryLevel = 0 // SmallestMemory is the smallest possible MemoryLevel. As MemoryLevel // increases from 1 (SmallestMemory) to 9 (FastestMemory), the amount // of memory used doubles with each increase. SmallestMemory MemoryLevel = 1 // FastestMemory is the largest possible MemoryLevel. As MemoryLevel // increases from 1 (SmallestMemory) to 9 (FastestMemory), the amount // of memory used doubles with each increase. FastestMemory MemoryLevel = 9 )
func (MemoryLevel) GoString ¶
func (mlevel MemoryLevel) GoString() string
GoString returns the Go string representation of this MemoryLevel constant.
func (MemoryLevel) IsValid ¶
func (mlevel MemoryLevel) IsValid() bool
IsValid returns true if mlevel is a valid MemoryLevel constant.
func (MemoryLevel) MarshalJSON ¶
func (mlevel MemoryLevel) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON representation of this MemoryLevel constant.
func (*MemoryLevel) Parse ¶
func (mlevel *MemoryLevel) Parse(str string) error
Parse parses a string representation of a MemoryLevel constant.
func (MemoryLevel) String ¶
func (mlevel MemoryLevel) String() string
String returns the string representation of this MemoryLevel constant.
type Method ¶
type Method byte
Method indicates the compression method in use.
Currently, only DEFLATE compression is supported.
const ( // DeflateMethod indicates that DEFLATE compression should be used. DeflateMethod Method = iota // DefaultMethod requests that the default Method be used, which is // currently DeflateMethod. DefaultMethod = DeflateMethod )
func (Method) MarshalJSON ¶
MarshalJSON returns the JSON representation of this Method constant.
type NoOpTracer ¶
type NoOpTracer struct{}
NoOpTracer is an implementation of Tracer that does nothing.
type OSType ¶
type OSType byte
OSType indicates the OS or filesystem type on which a gzip-compressed file originated.
const ( // OSTypeUnknown indicates that the originating OS and/or filesystem is // not known. OSTypeUnknown OSType = iota // OSTypeFAT indicates that the file originated on an MS-DOS or Microsoft // Windows host with a FAT-based filesystem such as FAT16 or FAT32. OSTypeFAT // OSTypeAmiga indicates that the file originated on an Amiga host. OSTypeAmiga // OSTypeVMS indicates that the file originated on a VMS host. OSTypeVMS // OSTypeUnix indicates that the file originated on a Unix host, or on a // host with a Unix-like filesystem. OSTypeUnix // OSTypeVMCMS indicates that the file originated on a VM/CMS host. OSTypeVMCMS // OSTypeAtariTOS indicates that the file originated on an Atari TOS // host. OSTypeAtariTOS // OSTypeHPFS indicates that the file originated on an OS/2 host with an // HPFS filesystem. OSTypeHPFS // OSTypeMacintosh indicates that the file originated on an Apple // Macintosh host (Classic or Mac OS X) with an HFS or HFS+ // filesystem. OSTypeMacintosh // OSTypeZSystem indicates that the file originated on an IBM Z/System host. OSTypeZSystem // OSTypeCPM indicates that the file originated on a CP/M host. OSTypeCPM // OSTypeTOPS20 indicates that the file originated on a TOPS-20 host. OSTypeTOPS20 // OSTypeNTFS indicates that the file originated on a Microsoft Windows NT // host with an NTFS filesystem. OSTypeNTFS // OSTypeQDOS indicates that the file originated on a QDOS host. OSTypeQDOS // OSTypeAcornRISCOS indicates that the file originated on an Acorn RISCOS // host. OSTypeAcornRISCOS )
func (OSType) MarshalJSON ¶
MarshalJSON returns the JSON representation of this OSType constant.
type Option ¶
type Option func(*options)
Option represents a configuration option for Reader or Writer.
func WithCompressLevel ¶
func WithCompressLevel(clevel CompressLevel) Option
WithCompressLevel specifies the CompressLevel to use (Writer). Ignored by Reader.
func WithDictionary ¶
WithDictionary specifies the pre-shared LZ77 dictionary to use (Writer) or to assume (Reader). May specify nil to abandon a previously used pre-shared dictionary.
func WithFormat ¶
WithFormat specifies the Format to write (Writer) or expected to be read (Reader).
func WithMemoryLevel ¶
func WithMemoryLevel(mlevel MemoryLevel) Option
WithMemoryLevel specifies the MemoryLevel to use (Reader, Writer).
func WithMethod ¶
WithMethod specifies the Method to use (Writer). Ignored by Reader.
func WithStrategy ¶
WithStrategy specifies the Strategy to use (Writer). Ignored by Reader.
func WithTracers ¶
WithTracers specifies the list of Tracer instances which will receive Events as compression (Writer) or decompression (Reader) proceeds. Completely replaces any previous list.
func WithWindowBits ¶
func WithWindowBits(wbits WindowBits) Option
WithWindowBits specifies the WindowBits to use (Writer) or the maximum WindowBits to expect (Reader).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps an io.Reader and decompresses the data which flows through it.
func NewReader ¶
NewReader constructs and returns a new Reader with the given io.Reader and options.
func (*Reader) Close ¶
Close terminates decompression and closes this Reader.
The underlying io.Reader is *not* closed, even if it supports io.Closer.
The only method which is guaranteed to be safe to call on a Reader after Close is Reset, which will return the Reader to a non-closed state.
func (*Reader) Dict ¶
Dict returns the pre-shared LZ77 dictionary which this Reader uses, or nil if no such dictionary is in use.
func (*Reader) MemoryLevel ¶
func (fr *Reader) MemoryLevel() MemoryLevel
MemoryLevel returns the MemoryLevel which this Reader uses.
func (*Reader) Read ¶
Read reads from the compressed stream into the provided slice of bytes. Conforms to the io.Reader interface.
func (*Reader) Reset ¶
Reset re-initializes this Reader with the given io.Reader and options. Any options given here are merged with all previous options.
func (*Reader) UnderlyingReader ¶
UnderlyingReader returns the io.Reader which this Reader uses.
func (*Reader) WindowBits ¶
func (fr *Reader) WindowBits() WindowBits
WindowBits returns the WindowBits which this Reader uses.
type SizeList ¶
type SizeList []byte
SizeList represents a list of symbol sizes in a Canonical Huffman Code.
func (SizeList) MarshalJSON ¶
MarshalJSON returns the JSON representation of this SizeList, as a JSON Array of JSON Numbers.
type Strategy ¶
type Strategy byte
Strategy indicates which compression strategy to use. Each strategy represents a different compression algorithm, but all available algorithms are compatible with the standard decompression algorithm.
const ( // DefaultStrategy indicates that the standard strategy be used. DefaultStrategy Strategy = iota // HuffmanOnlyStrategy indicates that LZ77 should not be used, only // Huffman coding. HuffmanOnlyStrategy // HuffmanRLEStrategy indicates that LZ77 should only be used for // run-length encoding (RLE), not for more complex history matching. HuffmanRLEStrategy // FixedStrategy indicates that all Huffman-encoded blocks should use // the static (pre-defined) Huffman encoding defined by the DEFLATE // standard, not the dynamic encodings that are optimal for each block. FixedStrategy )
func (Strategy) MarshalJSON ¶
MarshalJSON returns the JSON representation of this Strategy constant.
type Tracer ¶
type Tracer interface {
OnEvent(Event)
}
Tracer is an interface which callers can implement in order to receive Events. Events provide feedback on the progress of the compression or decompression operation.
func CaptureHeader ¶
CaptureHeader returns a Tracer implementation which will fill the pointed-to Header object when StreamHeaderEvent is encountered.
type TracerFunc ¶
type TracerFunc func(Event)
TracerFunc is an implementation of Tracer that calls a function.
type TreesEvent ¶
type TreesEvent struct { CodeCount uint16 LiteralLengthCount uint16 DistanceCount uint16 CodeSizes SizeList LiteralLengthSizes SizeList DistanceSizes SizeList }
TreesEvent is a sub-struct that is only present for BlockTreesEvent.
type WindowBits ¶
type WindowBits byte
WindowBits indicates the amount of RAM for the LZ77 sliding window to use.
const ( // DefaultWindowBits requests that the default value for WindowBits be // selected. This is equivalent to 15 (MaxWindowBits). DefaultWindowBits WindowBits = 0 // MinWindowBits is the smallest possible WindowBits. As WindowBits // increases from 8 (MinWindowBits) to 15 (MaxWindowBits), the amount // of memory used for the sliding window doubles with each increase. A // larger sliding window typically yields greater compression. MinWindowBits WindowBits = 8 // MaxWindowBits is the largest possible WindowBits. As WindowBits // increases from 8 (MinWindowBits) to 15 (MaxWindowBits), the amount // of memory used for the sliding window doubles with each increase. A // larger sliding window typically yields greater compression. MaxWindowBits WindowBits = 15 )
func (WindowBits) GoString ¶
func (wbits WindowBits) GoString() string
GoString returns the Go string representation of this WindowBits constant.
func (WindowBits) IsValid ¶
func (wbits WindowBits) IsValid() bool
IsValid returns true if wbits is a valid WindowBits constant.
func (WindowBits) MarshalJSON ¶
func (wbits WindowBits) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON representation of this WindowBits constant.
func (*WindowBits) Parse ¶
func (wbits *WindowBits) Parse(str string) error
Parse parses a string representation of a WindowBits constant.
func (WindowBits) String ¶
func (wbits WindowBits) String() string
String returns the string representation of this WindowBits constant.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer wraps an io.Writer and compresses the data which flows through it.
func NewWriter ¶
NewWriter constructs and returns a new Writer with the given io.Writer and options.
func (*Writer) Close ¶
Close finishes the compressed stream and closes this Writer.
The underlying io.Writer is *not* closed, even if it supports io.Closer.
The only method which is guaranteed to be safe to call on a Writer after Close is Reset, which will return the Writer to a non-closed state.
func (*Writer) CompressLevel ¶
func (fw *Writer) CompressLevel() CompressLevel
CompressLevel returns the CompressLevel which this Writer uses.
func (*Writer) Dict ¶
Dict returns the pre-shared LZ77 dictionary which this Writer uses, or nil if no such dictionary is in use.
func (*Writer) MemoryLevel ¶
func (fw *Writer) MemoryLevel() MemoryLevel
MemoryLevel returns the MemoryLevel which this Writer uses.
func (*Writer) Reset ¶
Reset re-initializes this Writer with the given io.Writer and options. Any options given here are merged with all previous options.
func (*Writer) UnderlyingWriter ¶
UnderlyingWriter returns the io.Writer which this Writer uses.
func (*Writer) WindowBits ¶
func (fw *Writer) WindowBits() WindowBits
WindowBits returns the WindowBits which this Writer uses.
Source Files ¶
- analysis.go
- bitwriter.go
- block64.go
- checksum32.go
- enum_blocktype.go
- enum_clevel.go
- enum_datatype.go
- enum_eventtype.go
- enum_flushtype.go
- enum_format.go
- enum_method.go
- enum_mlevel.go
- enum_ostype.go
- enum_strategy.go
- enum_wbits.go
- enum_writerstate.go
- errors.go
- header.go
- huffman.go
- options.go
- pools.go
- reader.go
- token.go
- trace.go
- util.go
- writer.go