lzma

package module
v0.0.0-...-2a7c55c Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2012 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Overview

The lzma package implements reading and writing of LZMA format compressed data. Reference implementation is LZMA SDK version 4.65 originaly developed by Igor Pavlov, available online at:

http://www.7-zip.org/sdk.html

Usage examples. Write compressed data to a buffer:

var b bytes.Buffer
w := lzma.NewWriter(&b)
w.Write([]byte("hello, world\n"))
w.Close()

read that data back:

r := lzma.NewReader(&b)
io.Copy(os.Stdout, r)
r.Close()

If the data is bigger than you'd like to hold into memory, use pipes. Write compressed data to an io.PipeWriter:

 pr, pw := io.Pipe()
 go func() {
 	defer pw.Close()
	w := lzma.NewWriter(pw)
	defer w.Close()
	// the bytes.Buffer would be an io.Reader used to read uncompressed data from
	io.Copy(w, bytes.NewBuffer([]byte("hello, world\n")))
 }()

and read it back:

defer pr.Close()
r := lzma.NewReader(pr)
defer r.Close()
// the os.Stdout would be an io.Writer used to write uncompressed data to
io.Copy(os.Stdout, r)

Index

Constants

View Source
const (
	BestSpeed          = 1
	BestCompression    = 9
	DefaultCompression = 5
)

Variables

This section is empty.

Functions

func NewReader

func NewReader(r io.Reader) io.ReadCloser

NewReader returns a new ReadCloser that can be used to read the uncompressed version of r. It is the caller's responsibility to call Close on the ReadCloser when finished reading.

func NewWriter

func NewWriter(w io.Writer) io.WriteCloser

Same as NewWriterSizeLevel(w, -1, DefaultCompression).

func NewWriterLevel

func NewWriterLevel(w io.Writer, level int) io.WriteCloser

Same as NewWriterSizeLevel(w, -1, level).

func NewWriterSize

func NewWriterSize(w io.Writer, size int64) io.WriteCloser

Same as NewWriterSizeLevel(w, size, DefaultCompression).

func NewWriterSizeLevel

func NewWriterSizeLevel(w io.Writer, size int64, level int) io.WriteCloser

NewWriterSizeLevel writes to the given Writer the compressed version of data written to the returned WriteCloser. It is the caller's responsibility to call Close on the WriteCloser when done. size is the actual size of uncompressed data that's going to be written to WriteCloser. If size is unknown, use -1 instead. level is any integer value between BestSpeed and BestCompression.

size and level (the lzma header) are written to w before any compressed data. If size is -1, last bytes are encoded in a different way to mark the end of the stream. The size of the compressed data will increase by 5 or 6 bytes.

Types

type Reader

type Reader interface {
	io.Reader
	ReadByte() (c byte, err error)
}

The actual read interface needed by NewDecoder. If the passed in io.Reader does not also have ReadByte, the NewDecoder will introduce its own buffering.

type Writer

type Writer interface {
	io.Writer
	Flush() error
	WriteByte(c byte) error
}

The actual write interface needed by NewEncoder. If the passed in io.Writer does not also have WriteByte and Flush, the NewEncoder will wrap it into an bufio.Writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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