为什么未按预期分配值?没有错误。
fs = require('fs');
var path="data.dat";
var f = fs.createReadStream(path,{highWaterMark:1024*1024*128})
var stat = fs.statSync(path);
var stream = fs.createReadStream(path,{start:0,end:stat.size-1});
var dat = new Float64Array(stat.size);
var idx = 0;
stream.on('data',(chunk)=>{
var temp = new Float64Array((new Uint8Array(chunk)).buffer);
for(var i = 0; i< temp.length;++i){
dat[idx++]=temp[i];
console.log(temp[i]); //this will log the expected values
console.log(dat[idx]); //this will log a bunch of 0
}
});
stream.on('end',function(){
//do_stuff(dat);
});
答案 0 :(得分:0)
Urrgg ......我觉得这很愚蠢。答案是console.log(dat [idx-1]);