pub struct HwpxEncoder;Expand description
Encodes Core documents to HWPX format (ZIP + XML).
This is the reverse of crate::HwpxDecoder: it takes a validated
document and an HwpxStyleStore and produces a valid HWPX archive.
§Round-trip
use hwpforge_smithy_hwpx::{HwpxDecoder, HwpxEncoder};
let bytes = std::fs::read("input.hwpx").unwrap();
let result = HwpxDecoder::decode(&bytes).unwrap();
let validated = result.document.validate().unwrap();
let output = HwpxEncoder::encode(&validated, &result.style_store, &result.image_store).unwrap();
std::fs::write("output.hwpx", &output).unwrap();§Image Binary Support
The encoder embeds binary image data from ImageStore into
BinData/ entries in the ZIP archive. Image paths in the document
(e.g. "BinData/image1.png") are matched against the store keys.
Images not found in the store are silently skipped (XML reference
only, no binary data).
Implementations§
Source§impl HwpxEncoder
impl HwpxEncoder
Sourcepub fn encode(
document: &Document<Validated>,
style_store: &HwpxStyleStore,
image_store: &ImageStore,
) -> HwpxResult<Vec<u8>>
pub fn encode( document: &Document<Validated>, style_store: &HwpxStyleStore, image_store: &ImageStore, ) -> HwpxResult<Vec<u8>>
Encodes a validated document with its style store and images to HWPX bytes.
The returned bytes form a valid ZIP archive that can be written
to a .hwpx file or decoded back with crate::HwpxDecoder.
§Pipeline
- Serialize
HwpxStyleStore→header.xml - Serialize each section →
section{N}.xml - Collect image binaries from
ImageStore - Package into ZIP with metadata files + BinData/
§Errors
HwpxError::XmlSerializeif quick-xml serialization failsHwpxError::InvalidStructureif table nesting exceeds limitsHwpxError::Zipif ZIP archive creation fails
Sourcepub fn encode_file(
path: impl AsRef<Path>,
document: &Document<Validated>,
style_store: &HwpxStyleStore,
image_store: &ImageStore,
) -> HwpxResult<()>
pub fn encode_file( path: impl AsRef<Path>, document: &Document<Validated>, style_store: &HwpxStyleStore, image_store: &ImageStore, ) -> HwpxResult<()>
Encodes a validated document and writes it to a file.
Convenience wrapper around encode +
std::fs::write.
§Errors
Returns HwpxError::Io if the file cannot be written, or any
error from encode.
Trait Implementations§
Source§impl Clone for HwpxEncoder
impl Clone for HwpxEncoder
Source§fn clone(&self) -> HwpxEncoder
fn clone(&self) -> HwpxEncoder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more