Documentation
¶
Overview ¶
Package content scans PDF content streams without allocating per operand.
A Scanner walks a decoded content stream one operation at a time. Operands are kept in a buffer the Scanner reuses: numbers are parsed in place, names and strings are slices of the stream (escapes are resolved on demand), and arrays and dictionaries are flattened into the same buffer. Operands are therefore only valid until the next call to Next.
Like go-pdfkit/reader's ContentScanner, broken content does not stop the scan: a malformed token is stepped over, counted, and the operations around it are still returned.
Index ¶
- Constants
- type Kind
- type Operand
- type Scanner
- func (s *Scanner) Arg(i int) *Operand
- func (s *Scanner) DictGet(o *Operand, key string) *Operand
- func (s *Scanner) Elems(o *Operand, f func(e *Operand) bool)
- func (s *Scanner) Errors() int
- func (s *Scanner) FromEnd(i int) *Operand
- func (s *Scanner) Image() (dict *Operand, data []byte)
- func (s *Scanner) Last() *Operand
- func (s *Scanner) Len() int
- func (s *Scanner) NameIs(o *Operand, n string) bool
- func (s *Scanner) Next() (op []byte, ok bool)
- func (s *Scanner) Nums(v []float64) bool
- func (s *Scanner) Op() []byte
- func (s *Scanner) Reset(data []byte)
- func (s *Scanner) Span() (start, end int)
- func (s *Scanner) Text(o *Operand) []byte
Constants ¶
const MaxNesting = 32
MaxNesting bounds nested arrays and dictionaries in one operand.
const MaxOperands = 1 << 12
MaxOperands bounds the operands kept for one operator; producers that emit more (a runaway TJ array is one operand) are truncated from the front, since operators take their operands from the end.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Operand ¶
type Operand struct {
Kind Kind
// Int reports that Num was written without a decimal point.
Int bool
// Num is the value of a Number, 1 or 0 for a Bool.
Num float64
// Raw is the unresolved text of a Name (without the slash), String or
// HexString. It points into the content stream.
Raw []byte
// contains filtered or unexported fields
}
Operand is one operand of an operation, or an element of an array or a dictionary operand.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner walks a content stream.
func (*Scanner) Elems ¶
Elems calls f for each element of an Array operand (or each key and value of a Dict operand, alternately) until f returns false.
func (*Scanner) Image ¶
Image returns the dictionary and the still-encoded data of the inline image of a BI operation.
func (*Scanner) Next ¶
Next advances to the next operation and returns its operator, or false at the end of the stream. The operator points into the stream.
func (*Scanner) Nums ¶
Nums reads the last len(v) operands, which must all be finite numbers, into v. Operators take their operands from the end, so surplus operands in front are ignored.