我正在用 GraphicsMagick 创建一个图像,然后我想在阅读它之前等待它被创建,这就是我尝试过的:
const fs = require('fs');
const { v5: uuidv5 } = require('uuid');
const readImage = async path => {
let uuid = uuidv5(path, uuidv5.DNS);
let path2 = 'images/' + uuid + '.png';
await gm(path).setFormat("png").colorspace('gray').write(path2, function (error) {
if (!error)
console.log("Finished converting " + path);
else
console.error(error);
});
const imageBuffer = await fs.readFileSync(path2);
return imageBuffer;
}
但目前它会在写入磁盘之前尝试读取它导致
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory
提前感谢您的答案