From 66a5e7c71a72cf2b0e3a6284b240722d325b606e Mon Sep 17 00:00:00 2001 From: bokuweb Date: Fri, 22 Apr 2022 15:24:15 +0900 Subject: [PATCH] 0.0.254 (#466) * fix: ignore unexist image * 0.0.254 --- docx-core/examples/reader.rs | 4 ++-- docx-core/src/reader/mod.rs | 8 +++++--- docx-wasm/package.json | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docx-core/examples/reader.rs b/docx-core/examples/reader.rs index b2baf30..3410672 100644 --- a/docx-core/examples/reader.rs +++ b/docx-core/examples/reader.rs @@ -4,11 +4,11 @@ use std::fs::File; use std::io::{Read, Write}; pub fn main() { - let mut file = File::open("./#3276.docx").unwrap(); + let mut file = File::open("./hello.docx").unwrap(); let mut buf = vec![]; file.read_to_end(&mut buf).unwrap(); - let mut file = File::create("./#3276.json").unwrap(); + let mut file = File::create("./hello.json").unwrap(); let res = read_docx(&buf).unwrap().json(); file.write_all(res.as_bytes()).unwrap(); file.flush().unwrap(); diff --git a/docx-core/src/reader/mod.rs b/docx-core/src/reader/mod.rs index 9a5ebdb..1213462 100644 --- a/docx-core/src/reader/mod.rs +++ b/docx-core/src/reader/mod.rs @@ -175,6 +175,7 @@ pub fn read_docx(buf: &[u8]) -> Result { let data = read_zip(&mut archive, "_rels/.rels")?; Rels::from_xml(&data[..])? }; + // Finally, the minimum content for the Main Document part must be defined // (physically located at /document.xml in the package): let main_rel = rels @@ -323,6 +324,7 @@ pub fn read_docx(buf: &[u8]) -> Result { docx.content_type = docx.content_type.add_footer(); } } + if let Some(ref f) = docx .document .section_property @@ -406,13 +408,13 @@ pub fn read_docx(buf: &[u8]) -> Result { docx = docx.web_settings(web_settings); } } - // Read media let media = rels.find_target_path(IMAGE_TYPE); if let Some(paths) = media { for (_, media) in paths { - let data = read_zip(&mut archive, media.to_str().expect("should have media"))?; - docx = docx.add_image(data); + if let Ok(data) = read_zip(&mut archive, media.to_str().expect("should have media")) { + docx = docx.add_image(data); + } } } Ok(docx) diff --git a/docx-wasm/package.json b/docx-wasm/package.json index f4821ab..c36940b 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.253", + "version": "0.0.254", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ",