From d080c5dd14ea1d0c66982232d799366c34e1429e Mon Sep 17 00:00:00 2001 From: d98762625 Date: Thu, 14 Mar 2019 08:27:06 +0000 Subject: [PATCH] debugging File shim --- src/core/Dish.mjs | 18 ++---------------- src/core/Utils.mjs | 4 ++++ src/core/dishTranslationTypes/DishFile.mjs | 7 ++++++- src/core/dishTranslationTypes/DishString.mjs | 2 ++ src/core/operations/Tar.mjs | 2 ++ src/node/File.mjs | 8 +++++++- src/node/api.mjs | 2 -- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/core/Dish.mjs b/src/core/Dish.mjs index 3e2aa651..104bbc2b 100755 --- a/src/core/Dish.mjs +++ b/src/core/Dish.mjs @@ -44,10 +44,6 @@ class Dish { if (dishOrInput && dishOrInput.hasOwnProperty("value") && dishOrInput.hasOwnProperty("type")) { - console.log('first setting'); - console.log(dishOrInput); - console.log(dishOrInput.constructor.name); - console.log(dishOrInput.value); this.set(dishOrInput.value, dishOrInput.type); // input and type defined separately } else if (dishOrInput && type) { @@ -103,8 +99,6 @@ class Dish { * @returns {string} The data type as a string. */ static enumLookup(typeEnum) { - console.trace('enumLookup'); - console.log('type ' + typeEnum); switch (typeEnum) { case Dish.BYTE_ARRAY: return "byteArray"; @@ -180,16 +174,11 @@ class Dish { type = Dish.typeEnum(type); } - console.log('Dish setting:'); - console.log(value); - console.log(type); - log.debug("Dish type: " + Dish.enumLookup(type)); this.value = value; this.type = type; if (!this.valid()) { - console.log('invalid!'); const sample = Utils.truncate(JSON.stringify(this.value), 13); throw new DishError(`Data is not a valid ${Dish.enumLookup(type)}: ${sample}`); } @@ -231,8 +220,6 @@ class Dish { // All values can be serialised in some manner, so we return true in all cases return true; case Dish.FILE: - console.log("Validating on file"); - console.log(this.value instanceof File); return this.value instanceof File; case Dish.LIST_FILE: return this.value instanceof Array && @@ -349,13 +336,13 @@ class Dish { // Node environment => translate is sync if (Utils.isNode()) { - console.log('_translate toType:'); - console.log(toType); + console.log('Running in node'); this._toByteArray(); this._fromByteArray(toType, notUTF8); // Browser environment => translate is async } else { + console.log('Running in browser'); return new Promise((resolve, reject) => { this._toByteArray() .then(() => this.type = Dish.BYTE_ARRAY) @@ -404,7 +391,6 @@ class Dish { }; try { - console.log("_tyByteArray this.type: " + this.type); return toByteArrayFuncs[Utils.isNode() && "node" || "browser"][this.type](); } catch (err) { throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to byteArray: ${err}`); diff --git a/src/core/Utils.mjs b/src/core/Utils.mjs index 3b44b60e..b61357de 100755 --- a/src/core/Utils.mjs +++ b/src/core/Utils.mjs @@ -967,6 +967,10 @@ class Utils { throw new TypeError("Browser environment cannot support readFileSync"); } + console.log('readFileSync:'); + console.log(file); + console.log(Buffer.from(file.data).toString()); + return Buffer.from(file.data).buffer; } diff --git a/src/core/dishTranslationTypes/DishFile.mjs b/src/core/dishTranslationTypes/DishFile.mjs index edf38b97..b04bd462 100644 --- a/src/core/dishTranslationTypes/DishFile.mjs +++ b/src/core/dishTranslationTypes/DishFile.mjs @@ -19,9 +19,12 @@ class DishFile extends DishTranslationType { static toByteArray() { DishFile.checkForValue(this.value); if (Utils.isNode()) { - console.log("valie: "); + console.log('toByteArray original value:'); console.log(this.value); + // this.value = Utils.readFileSync(this.value); this.value = Array.prototype.slice.call(Utils.readFileSync(this.value)); + console.log('toByteArray value:'); + console.log(this.value); } else { return new Promise((resolve, reject) => { Utils.readFile(this.value) @@ -40,6 +43,8 @@ class DishFile extends DishTranslationType { static fromByteArray() { DishFile.checkForValue(this.value); this.value = new File(this.value, "unknown"); + console.log('from Byte array'); + console.log(this.value); } } diff --git a/src/core/dishTranslationTypes/DishString.mjs b/src/core/dishTranslationTypes/DishString.mjs index 78c273c6..40b23001 100644 --- a/src/core/dishTranslationTypes/DishString.mjs +++ b/src/core/dishTranslationTypes/DishString.mjs @@ -17,8 +17,10 @@ class DishString extends DishTranslationType { * convert the given value to a ByteArray */ static toByteArray() { + console.log('string to byte array'); DishString.checkForValue(this.value); this.value = this.value ? Utils.strToByteArray(this.value) : []; + console.log(this.value); } /** diff --git a/src/core/operations/Tar.mjs b/src/core/operations/Tar.mjs index 84674bff..10748340 100644 --- a/src/core/operations/Tar.mjs +++ b/src/core/operations/Tar.mjs @@ -132,6 +132,8 @@ class Tar extends Operation { tarball.writeBytes(input); tarball.writeEndBlocks(); + console.log('Tar bytes'); + console.log(tarball.bytes); return new File([new Uint8Array(tarball.bytes)], args[0]); } diff --git a/src/node/File.mjs b/src/node/File.mjs index 768c46a8..938c8fd4 100644 --- a/src/node/File.mjs +++ b/src/node/File.mjs @@ -24,10 +24,16 @@ class File { * @param {Object} stats (optional) - file stats e.g. lastModified */ constructor(data, name="", stats={}) { - this.data = Buffer.from(data); + // Look at File API definition to see how to handle this. + this.data = Buffer.from(data[0]); this.name = name; this.lastModified = stats.lastModified || Date.now(); this.type = stats.type || mime.getType(this.name); + + console.log('File constructor'); + console.log(typeof data); + console.log(data); + console.log(this.data); } /** diff --git a/src/node/api.mjs b/src/node/api.mjs index dcc7eef3..ddd70ab1 100644 --- a/src/node/api.mjs +++ b/src/node/api.mjs @@ -197,8 +197,6 @@ export function wrap(OpClass) { wrapped = (input, args=null) => { const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args); const result = opInstance.run(transformedInput, transformedArgs); - console.log('Result:'); - console.log(result); return new NodeDish({ value: result, type: opInstance.outputType,