Documentation
¶
Overview ¶
Package lzo1z implements LZO1Z decompression in pure Go, with no cgo and no dependencies outside the standard library.
LZO1Z is one variant of Markus Oberhumer's LZO family. It shares LZO1X's block format but uses a 0x0700 M2 match offset instead of 0x0800, so the two are NOT interchangeable: feeding LZO1X data to this decoder yields either an error or silent corruption. If your producer calls lzo1x_* you want an LZO1X decoder, not this one.
Decompression only. There is no compressor here; use liblzo2 if you need to produce LZO1Z data.
dst := make([]byte, maxDecompressedSize)
n, err := lzo1z.Decompress(src, dst)
if err != nil {
return err
}
use(dst[:n])
The caller sizes dst. Decompress never grows it and returns ErrOutputOverrun rather than writing past the end, so an undersized buffer is a clean error and not a corruption. Every malformed-input path is checked: truncated input, output overrun, and a match offset pointing before the start of the output all return an error instead of reading or writing out of bounds.
Provenance ¶
This is a direct port of lzo1z_decompress from LZO 2.10 (lzo1x_d.ch with the LZO1Z branches, M2_MAX_OFFSET = 0x0700). Because it is a derivative of GPL code it is distributed under the GNU General Public License v2 or later; see the LICENSE file. Commercial licensing of LZO is available separately from the original author.
Correctness is pinned against vectors produced by liblzo2's own lzo1z_999_compress; see tools/genvectors to regenerate them.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Decompress ¶
Decompress decompresses one LZO1Z block from src into dst and returns the number of bytes written.
dst must be large enough to hold the entire decompressed block; LZO carries no length header, so the caller must know the bound out of band. Too small a dst returns ErrOutputOverrun with no partial success. Any trailing bytes in src after the end-of-stream marker return ErrNotConsumed.
Example ¶
package main
import (
"errors"
"fmt"
lzo1z "github.com/bandari-abhilash/LZO-GO"
)
func main() {
// "ABCDEFGHIJKLMNOPQR" as compressed by liblzo2's lzo1z_999_compress.
src := []byte{
0x23, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 0x11, 0x00, 0x00,
}
dst := make([]byte, 64*1024)
n, err := lzo1z.Decompress(src, dst)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s\n", dst[:n])
// An undersized dst is a clean error, never an out-of-bounds write.
_, err = lzo1z.Decompress(src, make([]byte, 4))
fmt.Println(errors.Is(err, lzo1z.ErrOutputOverrun))
}
Output: ABCDEFGHIJKLMNOPQR true
Types ¶
This section is empty.