lzw

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

README

Note

  • This is a consolidated version of compress/lzw that supports GIF, TIFF and PDF.
  • Please refer to this golang proposal for details.
  • pdfcpu also hosts an improved version of Go's TIFF package at github.com/hhrutter/pdfcpu/tiff leveraging the improved compress/lzw.

Background

  • PDF's LZWDecode filter comes with the optional parameter EarlyChange.
  • The type of this parameter is int and the defined values are 0 and 1.
  • The default value is 1.

This parameter implies two variants of lzw. (See the PDF spec).

compress/lzw:

  • the algorithm implied by EarlyChange value 1
  • provides both Reader and Writer.

golang.org/x/image/tiff/lzw (mirrored at):

  • the algorithm implied by EarlyChange value 0
  • provides a Reader, lacks a Writer

In addition PDF expects a leading clear_table marker right at the beginning which is not smth the stdlib compress/lzw does.

There are numerous PDF Writers out there and the following can be observed on arbitrary PDF files that use the LZWDecode filter:

  • Some PDF writers do not write the EOD (end of data) marker.
  • Some PDF writers do not write the final bits after the EOD marker.

Goal

A compress/lzw that works for a maximum number of components with a specific need for lzw support (as of now GIF, TIFF and PDF) and as a side effect of this an improved TIFF package that may or may not will make it into standard library one day.

Documentation

Overview

Package lzw is an enhanced version of compress/lzw.

It implements Adobe's PDF lzw compression as defined for the LZWDecode filter and is also compatible with the TIFF file format.

See the golang proposal: https://github.com/golang/go/issues/25409.

More information: https://github.com/hhrutter/pdfcpu/tree/master/lzw

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewReader

func NewReader(r io.Reader, oneOff bool) io.ReadCloser

NewReader creates a new io.ReadCloser. Reads from the returned io.ReadCloser read and decompress data from r. If r does not also implement io.ByteReader, the decompressor may read more data than necessary from r. It is the caller's responsibility to call Close on the ReadCloser when finished reading. oneOff makes code length increases occur one code early. It should be true for LZWDecode filters with earlyChange=1 which is also the default.

func NewWriter

func NewWriter(w io.Writer, oneOff bool) io.WriteCloser

NewWriter creates a new io.WriteCloser. Writes to the returned io.WriteCloser are compressed and written to w. It is the caller's responsibility to call Close on the WriteCloser when finished writing. oneOff makes code length increases occur one code early. It should be true for LZWDecode filters with earlyChange=1 which is also the default.

Types

This section is empty.

Jump to

Keyboard shortcuts

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