问题描述
未处理的拒绝(类型错误):预期 buffer
的类型为 Buffer
,但收到的类型为 object
push../node_modules/resize-img/index.js.module.exports
let pathi = fs.readFileSync(path.join(this.props.dir.server,"server-icon-0.png"));
console.log(pathi);
const image = await resizeImg(pathi,{
width: 64,height: 64,});
fs.writeFileSync(path.join(this.props.dir.server,"server-icon.png"),image);
记录 pathi
返回 Buffer
。
Buffer(77763)
它是一个 Uint8Array 的实例,其中显然有 77k+ 个数字。
解决方法
在 Anatoly 的帮助下找到了答案。
检查 pathi
是否真的是 Buffer
的实例,Buffer.isBuffer(pathi)
返回 false。使用 Buffer(pathi)
Buffer.isBuffer(Buffer(pathi))
构造新缓冲区后返回 true!