Added toStream export function

New Function returns a NodeJS readable stream that allows piping DOCX document data to stream.
This commit is contained in:
Matt Danner
2022-08-22 13:25:59 -07:00
committed by GitHub
parent 600fef21f6
commit 1a630bcb4d

View File

@ -1,4 +1,5 @@
import { File } from "@file/file";
import { Stream } from "stream";
import { Compiler } from "./next-compiler";
@ -45,6 +46,18 @@ export class Packer {
return zipData;
}
public static async toStream(file: File, prettify?: boolean | PrettifyType): Promise<Stream> {
const zip = this.compiler.compile(file, prettify);
const zipData = zip.generateNodeStream({
type: "nodebuffer",
streamFiles: true,
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
compression: "DEFLATE",
});
return zipData;
}
private static readonly compiler = new Compiler();
}