Moved bundle.mimeType behind a symbol + getter to prevent changing

This commit is contained in:
Alexander Cerutti
2021-10-16 18:05:29 +02:00
parent 868818b855
commit df683c37a8

View File

@@ -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.