From d5d5cb78b2707e9492dbd1f9bf26a9e79080f2f2 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Fri, 15 Oct 2021 11:26:32 +0200 Subject: [PATCH] Added bundle to messages --- spec/Bundle.ts | 3 ++- src/Bundle.ts | 3 ++- src/messages.ts | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/Bundle.ts b/spec/Bundle.ts index e7ed8e7..81f78c7 100644 --- a/spec/Bundle.ts +++ b/spec/Bundle.ts @@ -1,4 +1,5 @@ import { Stream } from "stream"; +import * as Messages from "../lib/messages"; import { default as Bundle, filesSymbol } from "../lib/Bundle"; describe("Bundle", () => { @@ -59,7 +60,7 @@ describe("Bundle", () => { expect(() => bundle.addBuffer("icon.png", Buffer.alloc(0)), - ).toThrowError(Error, "Cannot add file. Bundle is closed."); + ).toThrowError(Error, Messages.BUNDLE.CLOSED); }); }); diff --git a/src/Bundle.ts b/src/Bundle.ts index 1d3783f..d25d8d1 100644 --- a/src/Bundle.ts +++ b/src/Bundle.ts @@ -1,4 +1,5 @@ import { Stream } from "stream"; +import * as Messages from "./messages"; import { ZipFile } from "yazl"; export const filesSymbol = Symbol("bundleFiles"); @@ -87,7 +88,7 @@ export default class Bundle { public addBuffer(fileName: string, buffer: Buffer) { if (this.isFrozen) { - throw new Error("Cannot add file. Bundle is closed."); + throw new Error(Messages.BUNDLE.CLOSED); } this[filesSymbol][fileName] = buffer; diff --git a/src/messages.ts b/src/messages.ts index 7c9db5c..c20742d 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -73,6 +73,10 @@ export const MODELS = { FILE_NO_OPEN: "Cannot open model file. %s", } as const; +export const BUNDLE = { + CLOSED: "Cannot add file. Bundle is closed.", +} as const; + /** * Creates a message with replaced values * @param messageName