Imports #
"bufio"
"errors"
"fmt"
"io"
"bufio"
"errors"
"fmt"
"io"
"bufio"
"errors"
"fmt"
"io"
"bufio"
"errors"
"fmt"
"io"
LSB means Least Significant Bits first, as used in the GIF file format.
const LSB Order = iota
MSB means Most Significant Bits first, as used in the TIFF and PDF file formats.
const MSB
const decoderInvalidCode = 0xffff
var errClosed = *ast.CallExpr
errOutOfCodes is an internal error that means that the writer has run out of unused codes and a clear code needs to be sent next.
var errOutOfCodes = *ast.CallExpr
const flushBuffer = *ast.BinaryExpr
const invalidCode = *ast.BinaryExpr
A hash table entry is a uint32. Zero is an invalid entry since the lower 12 bits of a valid entry must be a non-literal code.
const invalidEntry = 0
A code is a 12 bit value, stored as a uint32 when encoding to avoid type conversions when shifting bits.
const maxCode = *ast.BinaryExpr
const maxWidth = 12
const tableMask = *ast.BinaryExpr
There are 1<<12 possible codes, which is an upper bound on the number of valid hash table entries at any given point in time. tableSize is 4x that.
const tableSize = *ast.BinaryExpr
Order specifies the bit ordering in an LZW data stream.
type Order int
A writer is a buffered, flushable writer.
type writer interface {
io.ByteWriter
Flush() error
}
Reader is an io.Reader which can be used to read compressed data in the LZW format.
type Reader struct {
r io.ByteReader
bits uint32
nBits uint
width uint
read func(*Reader) (uint16, error)
litWidth int
err error
clear uint16
eof uint16
hi uint16
overflow uint16
last uint16
suffix [*ast.BinaryExpr]uint8
prefix [*ast.BinaryExpr]uint16
output [*ast.BinaryExpr]byte
o int
toRead []byte
}
Writer is an LZW compressor. It writes the compressed form of the data to an underlying writer (see [NewWriter]).
type Writer struct {
w writer
litWidth uint
order Order
write func(*Writer, uint32) error
nBits uint
width uint
bits uint32
hi uint32
overflow uint32
savedCode uint32
err error
table [tableSize]uint32
}
Close closes the [Writer], flushing any pending output. It does not close w's underlying writer.
func (w *Writer) Close() error
Close closes the [Reader] and returns an error for any future read operation. It does not close the underlying [io.Reader].
func (r *Reader) Close() error
NewReader creates a new [io.ReadCloser]. Reads from the returned [io.ReadCloser] read and decompress data from r. If r does not also implement [io.ByteReader], the decompressor may read more data than necessary from r. It is the caller's responsibility to call Close on the ReadCloser when finished reading. The number of bits to use for literal codes, litWidth, must be in the range [2,8] and is typically 8. It must equal the litWidth used during compression. It is guaranteed that the underlying type of the returned [io.ReadCloser] is a *[Reader].
func NewReader(r io.Reader, order Order, litWidth int) io.ReadCloser
NewWriter creates a new [io.WriteCloser].
Writes to the returned [io.WriteCloser] are compressed and written to w.
It is the caller's responsibility to call Close on the WriteCloser when
finished writing.
The number of bits to use for literal codes, litWidth, must be in the
range [2,8] and is typically 8. Input bytes must be less than 1<func NewWriter(w io.Writer, order Order, litWidth int) io.WriteCloser
Read implements io.Reader, reading uncompressed bytes from its underlying [Reader].
func (r *Reader) Read(b []byte) (int, error)
Reset clears the [Writer]'s state and allows it to be reused again as a new [Writer].
func (w *Writer) Reset(dst io.Writer, order Order, litWidth int)
Reset clears the [Reader]'s state and allows it to be reused again as a new [Reader].
func (r *Reader) Reset(src io.Reader, order Order, litWidth int)
Write writes a compressed representation of p to w's underlying writer.
func (w *Writer) Write(p []byte) (n int, err error)
decode decompresses bytes from r and leaves them in d.toRead. read specifies how to decode bytes into codes. litWidth is the width in bits of literal codes.
func (r *Reader) decode()
incHi increments e.hi and checks for both overflow and running out of unused codes. In the latter case, incHi sends a clear code, resets the writer state and returns errOutOfCodes.
func (w *Writer) incHi() error
func (r *Reader) init(src io.Reader, order Order, litWidth int)
func (w *Writer) init(dst io.Writer, order Order, litWidth int)
func newReader(src io.Reader, order Order, litWidth int) *Reader
func newWriter(dst io.Writer, order Order, litWidth int) *Writer
readLSB returns the next code for "Least Significant Bits first" data.
func (r *Reader) readLSB() (uint16, error)
readMSB returns the next code for "Most Significant Bits first" data.
func (r *Reader) readMSB() (uint16, error)
writeLSB writes the code c for "Least Significant Bits first" data.
func (w *Writer) writeLSB(c uint32) error
writeMSB writes the code c for "Most Significant Bits first" data.
func (w *Writer) writeMSB(c uint32) error
Generated with Arrow