lzw

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package lzw implements the Lempel-Ziv-Welch compressed data format. This is the format described in T. A. Welch, “A Technique for High-Performance Data Compression”, Computer, 17(6) (June 1984), pp 8-19.

In particular, the package implements LZW as used by the PDF file format, which means variable-width codes up to 12 bits and the first two non-literal codes are a clear code and an EOF code. Both the correct and the "early change" variant are implemented.

The main differences to the compress/lzw package are:

  • the pdf/lzw package sends a clear code as the first code (required for Preview on MacOS)
  • pdf/lzw optionally implements the "early change" variant
  • pdf/lzw always uses MSB bit order and 8-bit literals

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader is an io.Reader which can be used to read compressed data in the LZW format.

func NewReader

func NewReader(src io.Reader, earlyChange bool) *Reader

NewReader creates a new io.ReadCloser. Reads from the returned io.ReadCloser read and decompress data from src. If src does not also implement io.ByteReader, the decompressor may read more data than necessary from src. It is the caller's responsibility to call [Close] on the ReadCloser when finished reading.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the Reader and returns an error for any future read operation. It does not close the underlying io.Reader.

func (*Reader) Read

func (r *Reader) Read(b []byte) (int, error)

Read implements io.Reader, reading uncompressed bytes from its underlying Reader.

type Writer

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

Writer is an LZW compressor. It writes the compressed form of the data to an underlying writer (see NewWriter).

func NewWriter

func NewWriter(dst io.Writer, earlyChange bool) (*Writer, error)

NewWriter creates a new io.WriteCloser. Writes to the returned io.WriteCloser are compressed and written to dst. It is the caller's responsibility to call Close on the WriteCloser when finished writing.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the Writer, flushing any pending output. It does not close w's underlying writer.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write writes a compressed representation of p to w's underlying writer.

Jump to

Keyboard shortcuts

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