mirror of
https://github.com/gchq/CyberChef
synced 2025-12-10 21:33:36 +00:00
Change run() functions to be async
This commit is contained in:
@@ -36,27 +36,14 @@ class DitherImage extends Operation {
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
async run(input, args) {
|
||||
const type = Magic.magicFileType(input);
|
||||
|
||||
if (type && type.mime.indexOf("image") === 0){
|
||||
return new Promise((resolve, reject) => {
|
||||
jimp.read(Buffer.from(input))
|
||||
.then(image => {
|
||||
image
|
||||
.dither565()
|
||||
.getBuffer(jimp.AUTO, (error, result) => {
|
||||
if (error){
|
||||
reject(new OperationError("Error getting the new image buffer"));
|
||||
} else {
|
||||
resolve([...result]);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
reject(new OperationError("Error applying a dither effect to the image."));
|
||||
});
|
||||
});
|
||||
const image = await jimp.read(Buffer.from(input));
|
||||
image.dither565();
|
||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||
return [...imageBuffer];
|
||||
} else {
|
||||
throw new OperationError("Invalid file type.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user