Files
docx-js/ts/export/packer/packer.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-03-31 18:07:22 +01:00
import * as archiver from "archiver";
2016-03-31 19:28:12 +01:00
import * as fs from "fs";
import {Formatter} from "../formatter";
import {Document} from "../../docx";
import {Style} from "../../style";
import {Properties} from "../../properties";
2016-03-31 15:49:42 +01:00
2016-03-31 19:28:12 +01:00
export abstract class Packer {
2016-03-31 18:07:22 +01:00
protected archive: any;
2016-03-31 19:28:12 +01:00
private formatter: Formatter;
protected document: Document;
2016-04-03 05:28:37 +01:00
private style: Style;
private properties: Properties;
2016-03-31 18:03:16 +01:00
constructor(document: Document, style: Style, properties: Properties) {
2016-03-31 19:28:12 +01:00
this.formatter = new Formatter();
this.document = document;
2016-04-03 05:28:37 +01:00
this.style = style;
this.properties = properties;
2016-03-31 18:07:22 +01:00
this.archive = archiver.create("zip", {});
2016-03-31 19:04:54 +01:00
this.archive.on('error', (err) => {
throw err;
});
2016-03-31 18:03:16 +01:00
}
2016-03-31 19:28:12 +01:00
pack(output: any): void {
2016-03-31 18:03:16 +01:00
this.archive.pipe(output);
this.archive.bulk([
{
expand: true,
cwd: __dirname + '/template',
src: ['**', '**/.rels']
}
]);
2016-03-31 19:04:54 +01:00
//this.archive.directory(__dirname + "/template", "/");
2016-04-03 05:28:37 +01:00
this.archive.append(this.document, {
name: 'word/document.xml'
});
this.archive.append(this.style, {
name: 'word/newStyle.xml'
});
this.archive.append(this.properties, {
name: 'docProps/core.xml'
});
2016-03-31 19:04:54 +01:00
this.archive.finalize();
2016-03-31 18:03:16 +01:00
}
2016-03-31 15:45:48 +01:00
}