From df683c37a89f5f3623e94c13e84001f4443f37ad Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 16 Oct 2021 18:05:29 +0200 Subject: [PATCH] Moved bundle.mimeType behind a symbol + getter to prevent changing --- src/Bundle.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Bundle.ts b/src/Bundle.ts index 5337965..ee3bc2d 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -4,6 +4,7 @@ import * as zip from "do-not-zip"; export const filesSymbol = Symbol("bundleFiles"); export const freezeSymbol = Symbol("bundleFreeze"); +export const mimeTypeSymbol = Symbol("bundleMimeType"); namespace Mime { export type type = string; @@ -18,11 +19,14 @@ namespace Mime { export default class Bundle { private [filesSymbol]: { [key: string]: Buffer } = {}; + private [mimeTypeSymbol]: string; - constructor(public mimeType: `${Mime.type}/${Mime.subtype}`) { + constructor(mimeType: `${Mime.type}/${Mime.subtype}`) { if (!mimeType) { throw new Error(Messages.BUNDLE.MIME_TYPE_MISSING); } + + this[mimeTypeSymbol] = mimeType; } /** @@ -53,6 +57,14 @@ export default class Bundle { return [bundle, () => bundle[freezeSymbol]()]; } + /** + * Retrieves bundle's mimeType + */ + + public get mimeType() { + return this[mimeTypeSymbol]; + } + /** * Freezes the bundle so no more files * can be added any further.