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
- func NewReader(r io.Reader) io.ReadCloser
- func NewWriter(w io.Writer) io.WriteCloser
- func NewWriterLevel(w io.Writer, level int) io.WriteCloser
- func NewWriterSize(w io.Writer, size int64) io.WriteCloser
- func NewWriterSizeLevel(w io.Writer, size int64, level int) io.WriteCloser
- type Reader
- type Writer
Constants ¶
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 ¶
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.