From 1b3647da8fe1083c7eaaaf6882f1897960403524 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sun, 26 Sep 2021 18:17:24 +0200 Subject: [PATCH] Added Bundle.prototype.isFrozen getter and used it to close pass if it is not yet frozen --- src/Bundle.ts | 13 +++++++++++-- src/PKPass.ts | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Bundle.ts b/src/Bundle.ts index 6580e0b..6727046 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -61,7 +61,7 @@ export default class Bundle { */ protected freeze() { - if (this[bundleStateSymbol] === BundleState.CLOSED) { + if (this.isFrozen) { return; } @@ -69,6 +69,15 @@ export default class Bundle { this[archiveSymbol].end(); } + /** + * Tells if this bundle still allows files to be added + * @returns + */ + + public get isFrozen() { + return this[bundleStateSymbol] === BundleState.CLOSED; + } + /** * Allows files to be added to the bundle. * If the bundle is closed, it will throw an error. @@ -78,7 +87,7 @@ export default class Bundle { */ public addBuffer(fileName: string, buffer: Buffer) { - if (this[bundleStateSymbol] === BundleState.CLOSED) { + if (this.isFrozen) { throw new Error("Cannot add file. Bundle is closed."); } diff --git a/src/PKPass.ts b/src/PKPass.ts index 72389c3..ec9e26e 100644 --- a/src/PKPass.ts +++ b/src/PKPass.ts @@ -465,7 +465,9 @@ export default class PKPass extends Bundle { * @TODO warning if no icon files */ - this[closePassSymbol](); + if (!this.isFrozen) { + this[closePassSymbol](); + } return super.getAsBuffer(); } @@ -486,7 +488,9 @@ export default class PKPass extends Bundle { * @TODO warning if no icon files */ - this[closePassSymbol](); + if (!this.isFrozen) { + this[closePassSymbol](); + } return super.getAsStream(); }