NodeJS writeStream空文件 [英] NodeJS writeStream empty file
问题描述
$ b
var buff = new Buffer( base64data, '的base64');
console.log(base64data);
var stream = fs.createWriteStream('/ path / to / thefile.png');
stream.write(buff)
stream.end()
然而,结果文件是空的。
当我输出 console.log(base64data);
并解码它在本地,它产生一个有效的png二进制文件,为什么文件是空的?
该文件是一个3600x4800 px png文件(即它是巨大的),这可能是一个因素?
另外,我还试过 writeFile
,没有运气。
是的, fs
是 require('fs')
谢谢
你的stream.end()没有写任何东西。它是异步函数记住。
var buff = new Buffer(base64data,'base64');
console.log(base64data);
var stream = fs.createWriteStream('/ path / to / thefile.png');
stream.write(buff);
stream.on(end,function(){
stream.end();
});
I am trying to use nodeJS to save a processed image stored in a base64 string.
var buff = new Buffer(base64data,'base64');
console.log(base64data);
var stream = fs.createWriteStream('/path/to/thefile.png');
stream.write(buff)
stream.end()
However, the resulting file is empty.
When I take the output of console.log(base64data);
and decode it locally, it produces a valid png binary, so why is the file empty?
The file is a 3600x4800 px png file (i.e. it's huge), could this be a factor?
Also, I tried writeFile
as well, no luck.
And yes, fs
is require('fs')
Thanks
your stream.end() too soon as nothing is written. it is async function remember.
var buff = new Buffer(base64data,'base64');
console.log(base64data);
var stream = fs.createWriteStream('/path/to/thefile.png');
stream.write(buff);
stream.on("end", function() {
stream.end();
});
这篇关于NodeJS writeStream空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!