mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-24 00:36:16 -04:00
Remove Buffer from Dish. Convert into ByteArray in api and then pass in as ArrayBuffer. Add some PNG files to tests
This commit is contained in:
parent
20bb104006
commit
55f7cac526
3 changed files with 14 additions and 45 deletions
|
@ -61,8 +61,6 @@ class Dish {
|
|||
return Dish.FILE;
|
||||
case "list<file>":
|
||||
return Dish.LIST_FILE;
|
||||
case "buffer":
|
||||
return Dish.BUFFER;
|
||||
default:
|
||||
throw "Invalid data type string. No matching enum.";
|
||||
}
|
||||
|
@ -95,8 +93,6 @@ class Dish {
|
|||
return "File";
|
||||
case Dish.LIST_FILE:
|
||||
return "List<File>";
|
||||
case Dish.BUFFER:
|
||||
return "Buffer";
|
||||
default:
|
||||
throw "Invalid data type enum. No matching type.";
|
||||
}
|
||||
|
@ -270,8 +266,6 @@ class Dish {
|
|||
case Dish.LIST_FILE:
|
||||
return this.value instanceof Array &&
|
||||
this.value.reduce((acc, curr) => acc && curr instanceof File, true);
|
||||
case Dish.BUFFER:
|
||||
return this.value instanceof Buffer;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -290,7 +284,6 @@ class Dish {
|
|||
case Dish.BYTE_ARRAY:
|
||||
case Dish.STRING:
|
||||
case Dish.HTML:
|
||||
case Dish.BUFFER:
|
||||
return this.value.length;
|
||||
case Dish.NUMBER:
|
||||
case Dish.BIG_NUMBER:
|
||||
|
@ -364,12 +357,6 @@ class Dish {
|
|||
this.type
|
||||
);
|
||||
break;
|
||||
case Dish.BUFFER:
|
||||
newDish.set(
|
||||
Buffer.from(this.value),
|
||||
this.type
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Cannot clone Dish, unknown type");
|
||||
}
|
||||
|
@ -434,12 +421,5 @@ Dish.FILE = 7;
|
|||
* @enum
|
||||
*/
|
||||
Dish.LIST_FILE = 8;
|
||||
/**
|
||||
* Dish data type enum for node Buffer.
|
||||
* @readonly
|
||||
* @enum
|
||||
*/
|
||||
Dish.BUFFER = 9;
|
||||
|
||||
|
||||
export default Dish;
|
||||
|
|
|
@ -108,15 +108,20 @@ function ensureIsDish(input) {
|
|||
dish.set(input, type);
|
||||
}
|
||||
return dish;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* prepareOp: transform args, make input the right type.
|
||||
* Also convert any Buffers to ArrayBuffers.
|
||||
* @param opInstance - instance of the operation
|
||||
* @param input - operation input
|
||||
* @param args - operation args
|
||||
*/
|
||||
function prepareOp(opInstance, input, args) {
|
||||
// convert any Buffers into ArrayBuffers.
|
||||
if (input instanceof Buffer) {
|
||||
input = input.buffer;
|
||||
}
|
||||
const dish = ensureIsDish(input);
|
||||
let transformedArgs;
|
||||
// Transform object-style args to original args array
|
||||
|
@ -127,7 +132,7 @@ function prepareOp(opInstance, input, args) {
|
|||
}
|
||||
const transformedInput = dish.get(opInstance.inputType);
|
||||
return {transformedInput, transformedArgs};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an operation to be consumed by node API.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue