pub struct DocxReader { /* private fields */ }Expand description
A streaming DOCX reader that implements EventSource.
DocxReader parses a DOCX archive and emits DocSpec events one at a time.
<w:p> paragraphs, <w:t> text, <w:br> line breaks, <w:tab> tabs,
table elements (<w:tbl>, <w:tr>, <w:tc>), and DrawingML images
(<w:drawing>) are recognized; all other elements are silently ignored.
§Streaming
Memory use depends on which constructor you call. from_path streams
word/document.xml in constant memory (O(1)). from_reader buffers
word/document.xml into memory (O(N) in document size). In both cases,
_rels/.rels and word/_rels/document.xml.rels are fully read into memory
at package-open time (typical combined size < 10 KB). The internal event
queue remains bounded regardless of document size or hyperlink count.
§Errors
Returns docspec_core::Error::Io for I/O failures and docspec_core::Error::Parse for malformed
archives or XML.
Implementations§
Source§impl DocxReader
impl DocxReader
Sourcepub fn from_path<P>(path: P) -> Result<Self>
pub fn from_path<P>(path: P) -> Result<Self>
Creates a DocxReader from a file path.
Streams word/document.xml in constant memory (O(1) in document size).
Prefer this over from_reader when memory is a concern.
§Errors
Returns docspec_core::Error::Io if the file cannot be opened. See from_reader
for additional error conditions.
Sourcepub fn from_reader<R>(reader: R) -> Result<Self>
pub fn from_reader<R>(reader: R) -> Result<Self>
Creates a DocxReader from any Read + Seek source.
The reader must be positioned at the start of a valid DOCX (ZIP) archive.
Memory note: this constructor buffers word/document.xml into memory
(O(N) in document size). Use from_path for O(1)
constant-memory streaming.
§Errors
Returns docspec_core::Error::Parse if the input is not a valid ZIP archive, if
_rels/.rels is missing or malformed, or if the document target entry
cannot be opened. Returns docspec_core::Error::Io for I/O failures.