pub struct ObjectStream { /* private fields */ }Expand description
A decoded object stream, ready for positional object lookup.
Constructed once per container by ObjectStream::parse and cached
by the document loader — decoding is the expensive part and a
container typically holds dozens to hundreds of objects, each of
which would otherwise re-inflate the whole thing.
Implementations§
Source§impl ObjectStream
impl ObjectStream
Sourcepub fn parse(dict: &Dict, raw: &[u8]) -> Result<Self, ObjStmError>
pub fn parse(dict: &Dict, raw: &[u8]) -> Result<Self, ObjStmError>
Decode raw through dict’s filter chain and read its Table 16
header and pair table.
dict is the container’s stream dictionary and raw its
still-encoded data_span bytes.
§Errors
ObjStmError — see the variants; each names the §7.5.7 rule
that was violated.
Sourcepub fn member_numbers(&self) -> impl Iterator<Item = u32> + '_
pub fn member_numbers(&self) -> impl Iterator<Item = u32> + '_
The object numbers this container holds, in stored (index) order.
Cheap: it reads the already-parsed pair table without decoding any
object value (unlike ObjectStream::object_at). It exists for
the cross-reference recovery path (crate::recover), which
rebuilds the type-2 (InStream) entries a lost xref would
otherwise have named — recovery needs only which numbers live in
which container at what index, exactly the type-2 entry’s fields
(§7.5.8.3 Table 18), and the pair table is the authority for that
(module docs). The index of each yielded number is its position in
the iterator, i.e. the type-2 entry’s field 3.
Sourcepub fn member_lengths(&self) -> Vec<usize>
pub fn member_lengths(&self) -> Vec<usize>
Decoded byte length of each member, in stored (index) order.
A member runs from its pair-table offset to the next larger offset, the
last to the end of the decoded data. The pair table and its separators,
which sit before /First, are not attributed to any member. Offsets
out of order or out of range yield 0 for that member rather than an
error: this answers “how much space”, a measurement, not a parse.
Sourcepub fn object_at(&self, index: usize) -> Result<(u32, Object), ObjStmError>
pub fn object_at(&self, index: usize) -> Result<(u32, Object), ObjStmError>
Parse the object stored at 0-based index, returning its
declared object number (from the pair table) and its value.
The object number is returned rather than assumed so the caller can cross-check it against the object number the type-2 cross-reference entry promised — a mismatch means the xref and the container disagree, which the strict loader refuses instead of silently trusting one of them.
§Errors
ObjStmError::IndexOutOfRange, ObjStmError::OffsetOutOfRange,
ObjStmError::Parse, or ObjStmError::SoleReference.