From 21f7662a770d93201ae4a8fca3bc365b7542ae7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20=C5=9Awi=C4=99s?= Date: Wed, 17 Aug 2022 18:52:19 +0200 Subject: [PATCH 1/2] Add toString to Packer --- src/export/packer/packer.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/export/packer/packer.ts b/src/export/packer/packer.ts index 56d604fe18..4d047f7381 100644 --- a/src/export/packer/packer.ts +++ b/src/export/packer/packer.ts @@ -13,6 +13,17 @@ export enum PrettifyType { } export class Packer { + public static async toString(file: File, prettify?: boolean | PrettifyType): Promise { + const zip = this.compiler.compile(file, prettify); + const zipData = await zip.generateAsync({ + type: "string", + mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + compression: "DEFLATE", + }); + + return zipData; + } + public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise { const zip = this.compiler.compile(file, prettify); const zipData = await zip.generateAsync({ From b6be05a931ab08e49a090b0a20efd4ef005ccd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20=C5=9Awi=C4=99s?= Date: Mon, 22 Aug 2022 19:08:29 +0200 Subject: [PATCH 2/2] Add test for Packer.toString --- src/export/packer/packer.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/export/packer/packer.spec.ts b/src/export/packer/packer.spec.ts index 5500144eff..b2c3e21836 100644 --- a/src/export/packer/packer.spec.ts +++ b/src/export/packer/packer.spec.ts @@ -37,6 +37,14 @@ describe("Packer", () => { }); }); + describe("#toString()", () => { + it("should return a non-empty string", async () => { + const result = await Packer.toString(file); + + assert.isAbove(result.length, 0); + }); + }); + describe("#toBuffer()", () => { it("should create a standard docx file", async function () { this.timeout(99999999);