From e9d7a8363cf7b4079b672aacf6dfc176dcd0f660 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 13 Jan 2023 14:38:50 +0000 Subject: [PATCH] Removed treatAsUTF8 option --- src/core/Chef.mjs | 5 ++--- src/core/Dish.mjs | 30 ++++++++++++---------------- src/core/dishTypes/DishBigNumber.mjs | 5 ++--- src/core/dishTypes/DishJSON.mjs | 5 ++--- src/core/dishTypes/DishNumber.mjs | 5 ++--- src/core/dishTypes/DishString.mjs | 5 ++--- src/core/dishTypes/DishType.mjs | 3 +-- src/web/html/index.html | 7 ------- src/web/index.js | 1 - 9 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/core/Chef.mjs b/src/core/Chef.mjs index 140774bc..dbde3e3f 100755 --- a/src/core/Chef.mjs +++ b/src/core/Chef.mjs @@ -41,8 +41,7 @@ class Chef { log.debug("Chef baking"); const startTime = Date.now(), recipe = new Recipe(recipeConfig), - containsFc = recipe.containsFlowControl(), - notUTF8 = options && "treatAsUtf8" in options && !options.treatAsUtf8; + containsFc = recipe.containsFlowControl(); let error = false, progress = 0; @@ -75,7 +74,7 @@ class Chef { return { dish: rawDish, - result: await this.dish.get(returnType, notUTF8), + result: await this.dish.get(returnType), type: Dish.enumLookup(this.dish.type), progress: progress, duration: Date.now() - startTime, diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index 1afdef01..11b1ff9f 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -128,10 +128,9 @@ class Dish { * If running in a browser, get is asynchronous. * * @param {number} type - The data type of value, see Dish enums. - * @param {boolean} [notUTF8=false] - Do not treat strings as UTF8. * @returns {* | Promise} - (Browser) A promise | (Node) value of dish in given type */ - get(type, notUTF8=false) { + get(type) { if (typeof type === "string") { type = Dish.typeEnum(type); } @@ -140,13 +139,13 @@ class Dish { // Node environment => _translate is sync if (isNodeEnvironment()) { - this._translate(type, notUTF8); + this._translate(type); return this.value; // Browser environment => _translate is async } else { return new Promise((resolve, reject) => { - this._translate(type, notUTF8) + this._translate(type) .then(() => { resolve(this.value); }) @@ -190,12 +189,11 @@ class Dish { * @Node * * @param {number} type - The data type of value, see Dish enums. - * @param {boolean} [notUTF8=false] - Do not treat strings as UTF8. * @returns {Dish | Promise} - (Browser) A promise | (Node) value of dish in given type */ - presentAs(type, notUTF8=false) { + presentAs(type) { const clone = this.clone(); - return clone.get(type, notUTF8); + return clone.get(type); } @@ -414,17 +412,16 @@ class Dish { * If running in the browser, _translate is asynchronous. * * @param {number} toType - The data type of value, see Dish enums. - * @param {boolean} [notUTF8=false] - Do not treat strings as UTF8. * @returns {Promise || undefined} */ - _translate(toType, notUTF8=false) { + _translate(toType) { log.debug(`Translating Dish from ${Dish.enumLookup(this.type)} to ${Dish.enumLookup(toType)}`); // Node environment => translate is sync if (isNodeEnvironment()) { this._toArrayBuffer(); this.type = Dish.ARRAY_BUFFER; - this._fromArrayBuffer(toType, notUTF8); + this._fromArrayBuffer(toType); // Browser environment => translate is async } else { @@ -486,18 +483,17 @@ class Dish { * Convert this.value to the given type from ArrayBuffer * * @param {number} toType - the Dish enum to convert to - * @param {boolean} [notUTF8=false] - Do not treat strings as UTF8. */ - _fromArrayBuffer(toType, notUTF8) { + _fromArrayBuffer(toType) { // Using 'bind' here to allow this.value to be mutated within translation functions const toTypeFunctions = { - [Dish.STRING]: () => DishString.fromArrayBuffer.bind(this)(notUTF8), - [Dish.NUMBER]: () => DishNumber.fromArrayBuffer.bind(this)(notUTF8), - [Dish.HTML]: () => DishHTML.fromArrayBuffer.bind(this)(notUTF8), + [Dish.STRING]: () => DishString.fromArrayBuffer.bind(this)(), + [Dish.NUMBER]: () => DishNumber.fromArrayBuffer.bind(this)(), + [Dish.HTML]: () => DishHTML.fromArrayBuffer.bind(this)(), [Dish.ARRAY_BUFFER]: () => {}, - [Dish.BIG_NUMBER]: () => DishBigNumber.fromArrayBuffer.bind(this)(notUTF8), - [Dish.JSON]: () => DishJSON.fromArrayBuffer.bind(this)(notUTF8), + [Dish.BIG_NUMBER]: () => DishBigNumber.fromArrayBuffer.bind(this)(), + [Dish.JSON]: () => DishJSON.fromArrayBuffer.bind(this)(), [Dish.FILE]: () => DishFile.fromArrayBuffer.bind(this)(), [Dish.LIST_FILE]: () => DishListFile.fromArrayBuffer.bind(this)(), [Dish.BYTE_ARRAY]: () => DishByteArray.fromArrayBuffer.bind(this)(), diff --git a/src/core/dishTypes/DishBigNumber.mjs b/src/core/dishTypes/DishBigNumber.mjs index d6f67698..3bb8122c 100644 --- a/src/core/dishTypes/DishBigNumber.mjs +++ b/src/core/dishTypes/DishBigNumber.mjs @@ -24,12 +24,11 @@ class DishBigNumber extends DishType { /** * convert the given value from a ArrayBuffer - * @param {boolean} notUTF8 */ - static fromArrayBuffer(notUTF8) { + static fromArrayBuffer() { DishBigNumber.checkForValue(this.value); try { - this.value = new BigNumber(Utils.arrayBufferToStr(this.value, !notUTF8)); + this.value = new BigNumber(Utils.arrayBufferToStr(this.value)); } catch (err) { this.value = new BigNumber(NaN); } diff --git a/src/core/dishTypes/DishJSON.mjs b/src/core/dishTypes/DishJSON.mjs index 703b0980..e1b32d64 100644 --- a/src/core/dishTypes/DishJSON.mjs +++ b/src/core/dishTypes/DishJSON.mjs @@ -22,11 +22,10 @@ class DishJSON extends DishType { /** * convert the given value from a ArrayBuffer - * @param {boolean} notUTF8 */ - static fromArrayBuffer(notUTF8) { + static fromArrayBuffer() { DishJSON.checkForValue(this.value); - this.value = JSON.parse(Utils.arrayBufferToStr(this.value, !notUTF8)); + this.value = JSON.parse(Utils.arrayBufferToStr(this.value)); } } diff --git a/src/core/dishTypes/DishNumber.mjs b/src/core/dishTypes/DishNumber.mjs index 8769a69a..e3ea31b8 100644 --- a/src/core/dishTypes/DishNumber.mjs +++ b/src/core/dishTypes/DishNumber.mjs @@ -23,11 +23,10 @@ class DishNumber extends DishType { /** * convert the given value from a ArrayBuffer - * @param {boolean} notUTF8 */ - static fromArrayBuffer(notUTF8) { + static fromArrayBuffer() { DishNumber.checkForValue(this.value); - this.value = this.value ? parseFloat(Utils.arrayBufferToStr(this.value, !notUTF8)) : 0; + this.value = this.value ? parseFloat(Utils.arrayBufferToStr(this.value)) : 0; } } diff --git a/src/core/dishTypes/DishString.mjs b/src/core/dishTypes/DishString.mjs index d7768859..7de8810d 100644 --- a/src/core/dishTypes/DishString.mjs +++ b/src/core/dishTypes/DishString.mjs @@ -23,11 +23,10 @@ class DishString extends DishType { /** * convert the given value from a ArrayBuffer - * @param {boolean} notUTF8 */ - static fromArrayBuffer(notUTF8) { + static fromArrayBuffer() { DishString.checkForValue(this.value); - this.value = this.value ? Utils.arrayBufferToStr(this.value, !notUTF8) : ""; + this.value = this.value ? Utils.arrayBufferToStr(this.value) : ""; } } diff --git a/src/core/dishTypes/DishType.mjs b/src/core/dishTypes/DishType.mjs index 849b5756..d89e3c0b 100644 --- a/src/core/dishTypes/DishType.mjs +++ b/src/core/dishTypes/DishType.mjs @@ -29,9 +29,8 @@ class DishType { /** * convert the given value from a ArrayBuffer - * @param {boolean} notUTF8 */ - static fromArrayBuffer(notUTF8=undefined) { + static fromArrayBuffer() { throw new Error("fromArrayBuffer has not been implemented"); } } diff --git a/src/web/html/index.html b/src/web/html/index.html index a5897840..a762ea96 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -483,13 +483,6 @@ -
- -
-