2018-08-14 01:46:48 +01:00
|
|
|
import { File } from "file";
|
|
|
|
import { Compiler } from "./next-compiler";
|
|
|
|
|
|
|
|
export class Packer {
|
|
|
|
private readonly compiler: Compiler;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.compiler = new Compiler();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async toBuffer(file: File): Promise<Buffer> {
|
2018-11-12 13:17:53 +00:00
|
|
|
const zip = this.compiler.compile(file);
|
2018-11-12 12:32:07 +00:00
|
|
|
const zipData = (await zip.generateAsync({
|
|
|
|
type: "nodebuffer",
|
|
|
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
|
})) as Buffer;
|
2018-08-14 01:46:48 +01:00
|
|
|
|
|
|
|
return zipData;
|
|
|
|
}
|
2018-01-31 20:08:36 +00:00
|
|
|
|
2018-08-14 01:46:48 +01:00
|
|
|
public async toBase64String(file: File): Promise<string> {
|
2018-11-12 13:17:53 +00:00
|
|
|
const zip = this.compiler.compile(file);
|
2018-11-12 12:32:07 +00:00
|
|
|
const zipData = (await zip.generateAsync({
|
|
|
|
type: "base64",
|
|
|
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
|
})) as string;
|
2018-08-14 01:46:48 +01:00
|
|
|
|
|
|
|
return zipData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async toBlob(file: File): Promise<Blob> {
|
2018-11-12 13:17:53 +00:00
|
|
|
const zip = this.compiler.compile(file);
|
2018-11-12 12:32:07 +00:00
|
|
|
const zipData = (await zip.generateAsync({
|
|
|
|
type: "blob",
|
|
|
|
mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
|
|
})) as Blob;
|
2018-08-14 01:46:48 +01:00
|
|
|
|
|
|
|
return zipData;
|
|
|
|
}
|
|
|
|
}
|