2018-08-14 01:46:48 +01:00
|
|
|
import { File } from "file";
|
|
|
|
import { Compiler } from "./next-compiler";
|
|
|
|
|
|
|
|
export class Packer {
|
2019-08-07 22:12:14 +01:00
|
|
|
public static async toBuffer(file: File, prettify?: boolean): Promise<Buffer> {
|
|
|
|
const zip = this.compiler.compile(file, prettify);
|
2019-08-15 00:48:36 +01:00
|
|
|
const zipData = await zip.generateAsync({
|
2018-11-12 12:32:07 +00:00
|
|
|
type: "nodebuffer",
|
|
|
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
2019-08-09 09:41:58 +02:00
|
|
|
compression: "DEFLATE",
|
2019-08-15 00:48:36 +01:00
|
|
|
});
|
2018-08-14 01:46:48 +01:00
|
|
|
|
|
|
|
return zipData;
|
|
|
|
}
|
2018-01-31 20:08:36 +00:00
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
public static async toBase64String(file: File, prettify?: boolean): Promise<string> {
|
|
|
|
const zip = this.compiler.compile(file, prettify);
|
2019-08-15 00:48:36 +01:00
|
|
|
const zipData = await zip.generateAsync({
|
2018-11-12 12:32:07 +00:00
|
|
|
type: "base64",
|
|
|
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
2019-08-09 09:41:58 +02:00
|
|
|
compression: "DEFLATE",
|
2019-08-15 00:48:36 +01:00
|
|
|
});
|
2018-08-14 01:46:48 +01:00
|
|
|
|
|
|
|
return zipData;
|
|
|
|
}
|
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
public static async toBlob(file: File, prettify?: boolean): Promise<Blob> {
|
|
|
|
const zip = this.compiler.compile(file, prettify);
|
2019-08-15 00:48:36 +01:00
|
|
|
const zipData = await zip.generateAsync({
|
2018-11-12 12:32:07 +00:00
|
|
|
type: "blob",
|
|
|
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
2019-08-09 09:41:58 +02:00
|
|
|
compression: "DEFLATE",
|
2019-08-15 00:48:36 +01:00
|
|
|
});
|
2018-08-14 01:46:48 +01:00
|
|
|
|
|
|
|
return zipData;
|
|
|
|
}
|
2019-08-07 22:12:14 +01:00
|
|
|
|
|
|
|
private static readonly compiler = new Compiler();
|
2018-08-14 01:46:48 +01:00
|
|
|
}
|