Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
const { data } = await this.imageData
const reader = new FileReader()
reader.readAsArrayBuffer(data)
// 先将文件下载到本地
const buffer = await new Promise(resolve => {
reader.onloadend = () => {
const buffer = Buffer.from(reader.result)
const filePath = path.resolve(IMAGE_SAVE_DIR, filename)
promisify(fs.writeFile)(filePath, buffer)
resolve(buffer)
}
})
// 拷贝到剪切板
if (isGif(buffer)) {
copyGif(filename)
} else {
clipboard.writeImage(nativeImage.createFromBuffer(buffer))
}
} catch (e) {
console.error(e)
// todo: error handler
}
}