Turn Packer static
This commit is contained in:
@ -2,14 +2,8 @@ import { File } from "file";
|
||||
import { Compiler } from "./next-compiler";
|
||||
|
||||
export class Packer {
|
||||
private readonly compiler: Compiler;
|
||||
|
||||
constructor(prettifyXml?: boolean) {
|
||||
this.compiler = new Compiler(prettifyXml);
|
||||
}
|
||||
|
||||
public async toBuffer(file: File): Promise<Buffer> {
|
||||
const zip = this.compiler.compile(file);
|
||||
public static async toBuffer(file: File, prettify?: boolean): Promise<Buffer> {
|
||||
const zip = this.compiler.compile(file, prettify);
|
||||
const zipData = (await zip.generateAsync({
|
||||
type: "nodebuffer",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
@ -18,8 +12,8 @@ export class Packer {
|
||||
return zipData;
|
||||
}
|
||||
|
||||
public async toBase64String(file: File): Promise<string> {
|
||||
const zip = this.compiler.compile(file);
|
||||
public static async toBase64String(file: File, prettify?: boolean): Promise<string> {
|
||||
const zip = this.compiler.compile(file, prettify);
|
||||
const zipData = (await zip.generateAsync({
|
||||
type: "base64",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
@ -28,8 +22,8 @@ export class Packer {
|
||||
return zipData;
|
||||
}
|
||||
|
||||
public async toBlob(file: File): Promise<Blob> {
|
||||
const zip = this.compiler.compile(file);
|
||||
public static async toBlob(file: File, prettify?: boolean): Promise<Blob> {
|
||||
const zip = this.compiler.compile(file, prettify);
|
||||
const zipData = (await zip.generateAsync({
|
||||
type: "blob",
|
||||
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
@ -37,4 +31,6 @@ export class Packer {
|
||||
|
||||
return zipData;
|
||||
}
|
||||
|
||||
private static readonly compiler = new Compiler();
|
||||
}
|
||||
|
Reference in New Issue
Block a user