lzo

package module
v0.0.0-...-f6d8204 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 12 Imported by: 0

README

lzo

lzo implements reading and writing of lzo format compressed files for Go, following lzop format. It uses the lzo C library underneath.

Installation

Download and install :

$ go get github.com/cyberdelia/lzo

Add it to your code :

import "github.com/cyberdelia/lzo"

Command line tool

Download and install:

$ go get github.com/cyberdelia/lzo/cmd/lzop

Compress and decompress:

$ lzop testdata/pg135.txt
$ lzop -d testdata/pg135.txt.lzo

Documentation

Index

Constants

View Source
const (
	// BestSpeed provides speed over better compression.
	BestSpeed = 3
	// BestCompression provides better compression over speed.
	BestCompression = 9
)

Variables

View Source
var (
	InputUnderrun      = errors.New("input underrun")
	LookBehindUnderrun = errors.New("lookbehind underrun")
)

Functions

func Compress1X

func Compress1X(in []byte) (out []byte, err error)

Compress an input buffer with LZO1X

func Compress1X999

func Compress1X999(in []byte) []byte

func Compress1X999Level

func Compress1X999Level(in []byte, level int) []byte

func Decompress1X

func Decompress1X(r io.Reader, inLen int, out []byte) (outLen int, err error)

Decompress an input compressed with LZO1X.

LZO1X has a stream terminator marker, so the decompression will always stop when this marker is found.

If inLen is not zero, it is expected to match the length of the compressed input stream, and it is used to limit reads from the underlying reader; if inLen is smaller than the real stream, the decompression will abort with an error; if inLen is larger than the real stream, or if it is zero, the decompression will succeed but more bytes than necessary might be read from the underlying reader. If the reader returns EOF before the termination marker is found, the decompression aborts and EOF is returned.

outLen is optional; if it's not zero, it is used as a hint to preallocate the output buffer to increase performance of the decompression.

Types

type Header struct {
	ModTime time.Time
	Name    string
	// contains filtered or unexported fields
}

Header metadata about the compressed file. This header is exposed as the fields of the Writer and Reader structs.

type Reader

type Reader struct {
	Header
	// contains filtered or unexported fields
}

A Reader is an io.Reader that can be read to retrieve uncompressed data from a lzop-format compressed file.

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader creates a new Reader reading the given reader.

func (*Reader) Close

func (z *Reader) Close() error

Close closes the Reader. It does not close the underlying io.Reader.

func (*Reader) Read

func (z *Reader) Read(p []byte) (int, error)

type Writer

type Writer struct {
	Header
	// contains filtered or unexported fields
}

A Writer is an io.Write that satisfies writes by compressing data written to its wrapped io.Writer.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new Writer that satisfies writes by compressing data written to w.

func NewWriterLevel

func NewWriterLevel(w io.Writer, level int) (*Writer, error)

NewWriterLevel is like NewWriter but specifies the compression level instead of assuming DefaultCompression.

func (*Writer) Close

func (z *Writer) Close() error

Close closes the Writer. It does not close the underlying io.Writer.

func (*Writer) Reset

func (z *Writer) Reset(w io.Writer)

Reset discards the Writer's state and makes it equivalent to the result of its original state from NewWriter or NewWriterLevel, but writing to w instead. This permits reusing a Writer rather than allocating a new one.

func (*Writer) Write

func (z *Writer) Write(p []byte) (int, error)

Write writes a compressed form of p to the underlying io.Writer.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL