Huge refactoring to use new compiler and deprecate all other Packers

Add new PdfPacker
This commit is contained in:
Dolan
2018-08-14 01:46:48 +01:00
parent 675192b86f
commit a38abeb4c2
19 changed files with 760 additions and 345 deletions

View File

@ -1,9 +1,31 @@
export interface IPacker {
pack(path: string): void;
}
import { File } from "file";
import { Compiler } from "./next-compiler";
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432
/**
* @ignore
*/
export const WORKAROUND = "";
export class Packer {
private readonly compiler: Compiler;
constructor() {
this.compiler = new Compiler();
}
public async toBuffer(file: File): Promise<Buffer> {
const zip = await this.compiler.compile(file);
const zipData = (await zip.generateAsync({ type: "nodebuffer" })) as Buffer;
return zipData;
}
public async toBase64String(file: File): Promise<string> {
const zip = await this.compiler.compile(file);
const zipData = (await zip.generateAsync({ type: "base64" })) as string;
return zipData;
}
public async toBlob(file: File): Promise<Blob> {
const zip = await this.compiler.compile(file);
const zipData = (await zip.generateAsync({ type: "blob" })) as Blob;
return zipData;
}
}