jw-hwp-core 0.1.2

Read-only parser for Hancom HWP 5.0 (binary CFB) and HWPX (OWPML) documents
Documentation
pub mod assets;
pub mod builder;
pub mod container;
pub(crate) mod dist;
pub mod doc_info;
pub mod error;
pub mod faces;
pub mod hwpx;
pub mod model;
pub mod ole_property;
pub mod reader;
pub mod record;
pub mod shape;
pub mod structure;
pub mod styles;
pub mod summary;
pub mod table;
pub mod text;

pub use doc_info::DocumentProperties;
pub use error::{Error, Warning, WarningCode};
pub use hwpx::writer::write_hwpx;
pub use model::{HwpDocument, Section};
pub use shape::{Align, CharShape, ParaShape, ShapeTables};
pub use structure::{NodeKind, StructureNode};
pub use summary::Metadata;
pub use table::{Cell, Table};

pub fn open(path: impl AsRef<std::path::Path>) -> Result<HwpDocument, Error> {
    let path = path.as_ref();
    // Sniff first 4 bytes: ZIP = HWPX, otherwise CFB (HWP 5.0).
    let mut magic = [0u8; 4];
    {
        use std::io::Read;
        let mut f = std::fs::File::open(path)?;
        let _ = f.read(&mut magic)?;
    }
    if magic == [0x50, 0x4B, 0x03, 0x04]
        || magic == [0x50, 0x4B, 0x05, 0x06]
        || magic == [0x50, 0x4B, 0x07, 0x08]
    {
        hwpx::read_hwpx(path)
    } else {
        reader::read_document(path)
    }
}