Move fs to exporter and add browser packer
This commit is contained in:
17
src/export/packer/browser.ts
Normal file
17
src/export/packer/browser.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Compiler } from "./next-compiler";
|
||||
import { IPacker } from "./packer";
|
||||
|
||||
declare var saveAs;
|
||||
|
||||
export class BrowserPacker implements IPacker {
|
||||
private readonly packer: Compiler;
|
||||
|
||||
public async pack(filePath: string): Promise<void> {
|
||||
filePath = filePath.replace(/.docx$/, "");
|
||||
|
||||
const zip = await this.packer.compile();
|
||||
const zipBlob = await zip.generateAsync({ type: "blob" });
|
||||
|
||||
saveAs(zipBlob, `${filePath}.docx`);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import * as archiver from "archiver";
|
||||
import * as express from "express";
|
||||
import * as fs from "fs";
|
||||
import { Writable } from "stream";
|
||||
import * as xml from "xml";
|
||||
|
||||
@ -89,7 +90,7 @@ export class Compiler {
|
||||
});
|
||||
|
||||
for (const data of this.file.Media.array) {
|
||||
this.archive.append(data.stream, {
|
||||
this.archive.append(fs.createReadStream(data.path), {
|
||||
name: `word/media/${data.fileName}`,
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user