diff --git a/spec/Bundle.ts b/spec/Bundle.ts index f77d645..2873b1d 100644 --- a/spec/Bundle.ts +++ b/spec/Bundle.ts @@ -1,5 +1,5 @@ import { Stream } from "stream"; -import { default as Bundle, filesSymbol } from "../lib/Bundle"; +import { default as Bundle } from "../lib/Bundle"; describe("Bundle", () => { let bundle: InstanceType; @@ -24,7 +24,7 @@ describe("Bundle", () => { const buffer = Buffer.alloc(0); bundle.addBuffer("pass.json", buffer); - expect(bundle[filesSymbol]).toEqual({ "pass.json": buffer }); + expect(bundle.files).toEqual({ "pass.json": buffer }); }); it("should throw error if freezed", async () => { diff --git a/src/Bundle.ts b/src/Bundle.ts index 6727046..935c877 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -1,7 +1,7 @@ import { Stream } from "stream"; import { ZipFile } from "yazl"; -export const filesSymbol = Symbol("bundleFiles"); +const filesSymbol = Symbol("bundleFiles"); const bundleStateSymbol = Symbol("state"); const archiveSymbol = Symbol("zip"); @@ -78,6 +78,14 @@ export default class Bundle { return this[bundleStateSymbol] === BundleState.CLOSED; } + /** + * Returns the list of files added to the bundle + */ + + public get files() { + return this[filesSymbol]; + } + /** * Allows files to be added to the bundle. * If the bundle is closed, it will throw an error. diff --git a/src/PKPass.ts b/src/PKPass.ts index ec9e26e..f18c70f 100644 --- a/src/PKPass.ts +++ b/src/PKPass.ts @@ -1,5 +1,5 @@ import FieldsArray from "./fieldsArray"; -import { default as Bundle, filesSymbol } from "./Bundle"; +import { default as Bundle } from "./Bundle"; import { getModelFolderContents } from "./parser"; import * as Schemas from "./schemas"; import { Stream } from "stream"; @@ -73,7 +73,7 @@ export default class PKPass extends Bundle { certificates = source.certificates; buffers = {}; - const buffersEntries = Object.entries(source[filesSymbol]); + const buffersEntries = Object.entries(source.files); /** Cloning all the buffers to prevent unwanted edits */ for (let i = 0; i < buffersEntries.length; i++) { @@ -285,7 +285,7 @@ export default class PKPass extends Bundle { } if (/pass\.json/.test(pathName)) { - if (this[filesSymbol]["pass.json"]) { + if (this.files["pass.json"]) { /** * Ignoring any further addition. In a * future we might consider merging instead @@ -374,7 +374,7 @@ export default class PKPass extends Bundle { } private [createManifestSymbol]() { - return Object.entries(this[filesSymbol]).reduce( + return Object.entries(this.files).reduce( (acc, [fileName, buffer]) => { const hashFlow = forge.md.sha1.create();