Documentation ¶
Overview ¶
Package meta implements the XFLATE meta encoding scheme.
The XFLATE meta encoding is a method of encoding arbitrary data into one or more RFC 1951 compliant DEFLATE blocks. This encoding has the special property that when the blocks are decoded by a RFC 1951 compliant decompressor, they produce absolutely no output. However, when decoded with the XFLATE meta decoder, it losslessly produces the original input.
The meta encoding works by encoding arbitrary data into the Huffman tree definition of dynamic DEFLATE blocks. These blocks have an empty data section and produce no output. Due to the Huffman definition overhead, the encoded output is usually larger than the input. However, for most input datasets, this encoding scheme is able to achieve an efficiency of at least 50%.
Index ¶
Constants ¶
const ( // MinRawBytes and MaxRawBytes are the theoretical minimum and maximum // number of bytes a block can encode. MinRawBytes = 0 MaxRawBytes = 31 // MinEncBytes and MaxEncBytes are the theoretical minimum and maximum // number of bytes an encoded block will occupy. MinEncBytes = 12 MaxEncBytes = 64 // EnsureRawBytes is the maximum number of bytes that a single block is // ensured to encode (computed using brute force). EnsureRawBytes = 22 )
These are some constants regarding the theoretical and practical limits for the meta encoding of a single block.
Variables ¶
This section is empty.
Functions ¶
func ReverseSearch ¶
ReverseSearch searches for a meta header in reverse. This returns the last index where the header was found. If not found, it returns -1.
Types ¶
type FinalMode ¶
type FinalMode int
FinalMode controls or indicates which final bits are set in the last block in the meta stream. In the meta encoding, there are 2 final bits:
Stream: This is the final bit from DEFLATE (as defined in RFC 1951). and indicates that the entire compression stream has come to an end. This bit indicate absolute termination of the stream. Meta: This final bit indicates that the current sequence of meta blocks has terminated. The decoded data from those blocks form a meta substream. This bit is used as a form of message framing for the meta encoding format.
It invalid for the stream final bit to be set, while the meta final bit is not set. All other combinations are legal.
type Reader ¶
type Reader struct { InputOffset int64 // Total number of bytes read from underlying io.Reader OutputOffset int64 // Total number of bytes emitted from Read NumBlocks int64 // Number of blocks decoded // FinalMode indicates which final bits (if any) were set. // This will be valid after a call to Close or upon hitting io.EOF. FinalMode FinalMode // contains filtered or unexported fields }
A Reader is an io.Reader that can read XFLATE's meta encoding. The zero value of Reader is valid once Reset is called.
func NewReader ¶
NewReader creates a new Reader reading from the given reader. If rd does not also implement compress.ByteReader or compress.BufferedReader, then the decoder may read more data than necessary from rd.
func (*Reader) Close ¶
Close ends the meta stream. The FinalMode encountered becomes valid after calling Close.
type Writer ¶
type Writer struct { InputOffset int64 // Total number of bytes issued to Write OutputOffset int64 // Total number of bytes written to underlying io.Writer NumBlocks int64 // Number of blocks encoded // FinalMode determines which final bits (if any) to set. // This must be set prior to a call to Close. FinalMode FinalMode // contains filtered or unexported fields }
A Writer is an io.Writer that can write XFLATE's meta encoding. The zero value of Writer is valid once Reset is called.
func NewWriter ¶
NewWriter creates a new Writer writing to the given writer. It is the caller's responsibility to call Close to complete the meta stream.
func (*Writer) Close ¶
Close ends the meta stream and flushes all buffered data. The desired FinalMode must be set prior to calling Close.