Package-Level Type Names (total 8, in which 1 are exported)
/* sort exporteds by: | */
A StructuralError is returned when the bzip2 data is found to be
syntactically invalid.
( T) Error() string
T : error
bitReader wraps an io.Reader and provides the ability to read values,
bit-by-bit, from it. Its Read* methods don't return the usual error
because the error handling was verbose. Instead, any error is kept and can
be checked afterwards.
bitsuinterrerrornuint64rio.ByteReader(*T) Err() error(*T) ReadBit() bool(*T) ReadBits(bits uint) (n int)
ReadBits64 reads the given number of bits and returns them in the
least-significant part of a uint64. In the event of an error, it returns 0
and the error can be obtained by calling Err().
func newBitReader(r io.Reader) bitReader
A huffmanNode is a node in the tree. left and right contain indexes into the
nodes slice of the tree. If left or right is invalidNodeValue then the child
is a left node and its value is in leftValue/rightValue.
The symbols are uint16s because bzip2 encodes not only MTF indexes in the
tree, but also two magic values for run-length encoding and an EOF symbol.
Thus there are more than 256 possible symbols.
leftuint16leftValueuint16rightuint16rightValueuint16
A huffmanTree is a binary tree which is navigated, bit-by-bit to reach a
symbol.
nextNodeint
nodes contains all the non-leaf nodes in the tree. nodes[0] is the
root of the tree and nextNode contains the index of the next element
of nodes to use when the tree is being constructed.
Decode reads bits from the given bitReader and navigates the tree until a
symbol is found.
func newHuffmanTree(lengths []uint8) (huffmanTree, error)
func buildHuffmanNode(t *huffmanTree, codes []huffmanCode, level uint32) (nodeIndex uint16, err error)
moveToFrontDecoder implements a move-to-front list. Such a list is an
efficient way to transform a string with repeating elements into one with
many small valued numbers, which is suitable for entropy encoding. It works
by starting with an initial list of symbols and references symbols by their
index into that list. When a symbol is referenced, it's moved to the front
of the list. Thus, a repeated symbol ends up being encoded with many zeros,
as the symbol will be at the front of the list after the first access.
( T) Decode(n int) (b byte)
First returns the symbol at the front of the list.
func newMTFDecoder(symbols []byte) moveToFrontDecoder
func newMTFDecoderWithRange(n int) moveToFrontDecoder
A reader decompresses bzip2 compressed data.
blockCRCuint32
// blockSize in bytes, i.e. 900 * 1000.
brbitReader
// the number of repeats of lastByte seen.
// the ``C'' array for the inverse BWT.
eofboolfileCRCuint32
// the last byte value seen.
// contains the RLE data still to be processed.
// number of entries of preRLE used.
// the number of copies of lastByte to output.
// true if we have parsed the bzip2 header.
// Index of the next output byte in tt.
// mirrors the ``tt'' array in the bzip2 source and contains the P array in the upper 24 bits.
wantBlockCRCuint32(*T) Read(buf []byte) (n int, err error)(*T) read(buf []byte) (int, error)
readBlock reads a bzip2 block. The magic number should already have been consumed.
(*T) readFromBlock(buf []byte) int
setup parses the bzip2 header.
*T : github.com/jbenet/go-context/io.Reader
*T : io.Reader
Package-Level Functions (total 9, in which 1 are exported)
NewReader returns an io.Reader which decompresses bzip2 data from r.
If r does not also implement io.ByteReader,
the decompressor may read more data than necessary from r.
buildHuffmanNode takes a slice of sorted huffmanCodes and builds a node in
the Huffman tree at the given level. It returns the index of the newly
constructed node.
inverseBWT implements the inverse Burrows-Wheeler transform as described in
http://www.hpl.hp.com/techreports/Compaq-DEC/SRC-RR-124.pdf, section 4.2.
In that document, origPtr is called ``I'' and c is the ``C'' array after the
first pass over the data. It's an argument here because we merge the first
pass with the Huffman decoding.
This also implements the ``single array'' method from the bzip2 source code
which leaves the output, still shuffled, in the bottom 8 bits of tt with the
index of the next byte in the top 24-bits. The index of the first byte is
returned.
newBitReader returns a new bitReader reading from r. If r is not
already an io.ByteReader, it will be converted via a bufio.Reader.
newHuffmanTree builds a Huffman tree from a slice containing the code
lengths of each symbol. The maximum code length is 32 bits.
newMTFDecoder creates a move-to-front decoder with an explicit initial list
of symbols.
newMTFDecoderWithRange creates a move-to-front decoder with an initial
symbol list of 0...n-1.
updateCRC updates the crc value to incorporate the data in b.
The initial value is 0.
Package-Level Variables (only one, which is unexported)
invalidNodeValue is an invalid index which marks a leaf node in the tree.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.