filter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package filter decodes PDF stream filters (ISO 32000-2 §7.4).

The five filters here are the ones needed to read text: Flate, LZW, ASCIIHex, ASCII85, and RunLength. The image filters — DCTDecode, CCITTFaxDecode, JBIG2Decode, JPXDecode — are deliberately absent. Image data is passed through still encoded so it can be written out in its original form without a lossy re-encode, which is what an image extractor wants.

That passthrough is the contract the image package is built on: it reads the codec off the chain this package stopped at, so a Flate-then-DCT stream reaches it as a decompressed JPEG that needs no further decoding to become a .jpg.

Decoding is owned rather than borrowed because it is small, entirely covered by the standard library, and sits on the hot path for every page.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("filter: unsupported")

ErrUnsupported is returned for a filter this package does not decode, including the image filters it deliberately leaves encoded.

Functions

func Decode

func Decode(name objects.Name, data []byte, params objects.Dict, s objects.Store) ([]byte, error)

Decode applies one filter to data. params may be nil.

func DecodeChain

func DecodeChain(st *objects.Stream, s objects.Store) ([]byte, error)

DecodeChain applies a stream's whole filter chain in order.

A chain stops at the first image filter, returning the data as it stands with the remaining filters reported. That is not a failure: it is how a Flate-then-DCT stream yields a decompressed JPEG.

func IsImage

func IsImage(name objects.Name) bool

IsImage reports whether name is an image filter whose data should be left encoded. Callers use this to distinguish "cannot decode" from "must not".

Types

This section is empty.

Jump to

Keyboard shortcuts

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