[英]Node same buffer on write stream
I have the following code我有以下代码
const buffer = new Buffer(buffer_size);
const wstream = fs.createWriteStream('testStream.ogg');
do{
read = obj1.partialDecrypt(buffer);
if(read>=0){
if(read<buffer_size){
wstream.write(buffer.slice(0,buffer_size));
}
else{
wstream.write(buffer);
}
}
total+=read;
}while(read>0);
wstream.end();
In which partialDecrypt fill the buffer with binary data and return the size filled.其中 partialDecrypt 用二进制数据填充缓冲区并返回填充的大小。 If I fill the buffer more than one time the data written to the stream does not match the expected.如果我多次填充缓冲区,则写入流的数据与预期不匹配。 Should I do something to reuse the same buffer on the stream?我应该做些什么来重用流上的相同缓冲区吗?
Turns out reusing buffer is not a good idea.结果证明重用缓冲区不是一个好主意。 Like on this thread , creating a new buffer each pass was the way to go.就像在这个线程上一样,每次通过创建一个新缓冲区是要走的路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.