View Source Pdf.Reader.ObjectStream (ExPDF v1.0.1)
Decodes objects embedded in a PDF Object Stream (/Type /ObjStm).
Per PDF 1.7 ISO 32000-1 § 7.5.7 "Object Streams":
An Object Stream is a stream whose decoded body has two parts:
- Header:
Nwhitespace-separated pairsobj_num offset, whereoffsetis the byte offset of that object's value relative to/First. - Object values: starting at byte
/First, theNobject bodies concatenated. Each body is a PDF value (integer, name, dictionary, array, etc.) but never a stream object — embedded streams are forbidden.
Caller contract
The caller (object resolver) is responsible for:
- Resolving the ObjStm indirect object itself.
- Decoding its filter chain (FlateDecode etc.) to get the raw body binary.
- Calling
fetch/3with the decoded body, the/Firstoffset, and the desired object's 0-based index within the stream.
This design avoids a circular dependency between the resolver and ObjStm: the resolver is stateful (cache), ObjStm is pure (binary in, value out).
Error reasons
{:error, :objstm_index_out_of_range}— index ≥ N (the object count).{:error, :malformed}— header cannot be parsed.
Summary
Functions
Fetch the PDF value at 0-based index from a decoded ObjStm body.
Functions
@spec fetch(non_neg_integer(), binary(), non_neg_integer()) :: {:ok, term()} | {:error, term()}
Fetch the PDF value at 0-based index from a decoded ObjStm body.
first is the /First value from the stream dictionary — the byte offset
within body where object data starts.
body is the decoded (filtered) stream body binary.
Returns {:ok, value} or {:error, reason}.