Added Bundle.prototype.isFrozen getter and used it to close pass if it is not yet frozen

This commit is contained in:
Alexander Cerutti
2021-09-26 18:17:24 +02:00
parent d41a592a69
commit 1b3647da8f
2 changed files with 17 additions and 4 deletions

View File

@@ -61,7 +61,7 @@ export default class Bundle {
*/ */
protected freeze() { protected freeze() {
if (this[bundleStateSymbol] === BundleState.CLOSED) { if (this.isFrozen) {
return; return;
} }
@@ -69,6 +69,15 @@ export default class Bundle {
this[archiveSymbol].end(); 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. * Allows files to be added to the bundle.
* If the bundle is closed, it will throw an error. * If the bundle is closed, it will throw an error.
@@ -78,7 +87,7 @@ export default class Bundle {
*/ */
public addBuffer(fileName: string, buffer: Buffer) { public addBuffer(fileName: string, buffer: Buffer) {
if (this[bundleStateSymbol] === BundleState.CLOSED) { if (this.isFrozen) {
throw new Error("Cannot add file. Bundle is closed."); throw new Error("Cannot add file. Bundle is closed.");
} }

View File

@@ -465,7 +465,9 @@ export default class PKPass extends Bundle {
* @TODO warning if no icon files * @TODO warning if no icon files
*/ */
if (!this.isFrozen) {
this[closePassSymbol](); this[closePassSymbol]();
}
return super.getAsBuffer(); return super.getAsBuffer();
} }
@@ -486,7 +488,9 @@ export default class PKPass extends Bundle {
* @TODO warning if no icon files * @TODO warning if no icon files
*/ */
if (!this.isFrozen) {
this[closePassSymbol](); this[closePassSymbol]();
}
return super.getAsStream(); return super.getAsStream();
} }