feat: add pack method

main
bokuweb 2019-11-11 10:41:59 +09:00
parent 69fc4e9048
commit 37d4a157d5
2 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,8 @@
use super::XMLDocProps;
use wasm_bindgen::prelude::*;
use crate::zipper;
use std::io::prelude::*;
use std::io::Seek;
#[derive(Debug)]
pub struct XMLDocx {
@ -9,3 +12,12 @@ pub struct XMLDocx {
pub styles: Vec<u8>,
pub document: Vec<u8>,
}
impl XMLDocx {
pub fn pack<W>(self, w: W) -> zip::result::ZipResult<()>
where
W: Write + Seek,
{
zipper::zip(w, self)
}
}

View File

@ -8,10 +8,10 @@ pub use types::*;
pub use zipper::*;
pub fn simple() {
let xml = Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new("Hello")))
.build();
let path = std::path::Path::new("./test.docx");
let file = std::fs::File::create(&path).unwrap();
zip(file, xml);
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new("Hello")))
.build()
.pack(file);
}