From a0f034b843acc4b375a110939b5dc4d72d253d83 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 1 Jun 2018 12:43:36 +0000 Subject: [PATCH] ESM: Fixed magic errors --- src/core/lib/Magic.mjs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/core/lib/Magic.mjs b/src/core/lib/Magic.mjs index 43e9dfe4..2be15144 100644 --- a/src/core/lib/Magic.mjs +++ b/src/core/lib/Magic.mjs @@ -229,17 +229,22 @@ class Magic { const testEnc = async op => { for (let i = 0; i < encodings.length; i++) { const conf = { - op: op, - args: [encodings[i]] - }, - data = await this._runRecipe([conf], sample.buffer); + op: op, + args: [encodings[i]] + }; - // Only add to the results if it changed the data - if (!_buffersEqual(data, sample.buffer)) { - results.push({ - data: data, - conf: conf - }); + try { + const data = await this._runRecipe([conf], sample.buffer); + + // Only add to the results if it changed the data + if (!_buffersEqual(data, sample.buffer)) { + results.push({ + data: data, + conf: conf + }); + } + } catch (err) { + continue; } } }; @@ -356,8 +361,9 @@ class Magic { * @returns {ArrayBuffer} */ async _runRecipe(recipeConfig, input=this.inputBuffer) { + input = input instanceof ArrayBuffer ? input : input.buffer; const dish = new Dish(); - dish.set(input.buffer, Dish.ARRAY_BUFFER); + dish.set(input, Dish.ARRAY_BUFFER); if (ENVIRONMENT_IS_WORKER()) self.loadRequiredModules(recipeConfig);