From 12a6781c149fc8f79597ec12cec0867a18e82c38 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Mon, 18 Oct 2021 23:54:24 +0200 Subject: [PATCH] Fixed Bundle methods calling javascript confusion: Bundle.getAsStream was calling this.getAsBuffer, but this was PKPass instance --- src/Bundle.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Bundle.ts b/src/Bundle.ts index ee3bc2d..812c415 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -113,12 +113,7 @@ export default class Bundle { public getAsBuffer(): Buffer { this[freezeSymbol](); - return zip.toBuffer( - Object.entries(this[filesSymbol]).map(([path, data]) => ({ - path, - data, - })), - ); + return zip.toBuffer(createZipFilesMap(this[filesSymbol])); } /** @@ -130,7 +125,10 @@ export default class Bundle { */ public getAsStream(): Stream { - return Readable.from(this.getAsBuffer()); + this[freezeSymbol](); + return Readable.from( + zip.toBuffer(createZipFilesMap(this[filesSymbol])), + ); } /** @@ -148,3 +146,17 @@ export default class Bundle { return Object.freeze({ ...this[filesSymbol] }); } } + +/** + * Creates a files map for do-not-zip + * + * @param files + * @returns + */ + +function createZipFilesMap(files: { [key: string]: Buffer }) { + return Object.entries(files).map(([path, data]) => ({ + path, + data, + })); +}