无法将值分配给类型化数组缓冲区

时间:2016-11-07 07:10:45

标签: javascript node.js variable-assignment typed-arrays

为什么未按预期分配值?没有错误。

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);
});

1 个答案:

答案 0 :(得分:0)

Urrgg ......我觉得这很愚蠢。答案是console.log(dat [idx-1]);