var rs = fs.createReadStream('data/soucd1.id.2014060113.grd’, { highWaterMark: 4,start: 0, end: 1821724 } ); rs.on("data", function (chunk){ console.log(chunk.readFloatBE(0,true)); });
我尝试用上面这种方式去做,可是读出来的数据好像不对,我对createReadStream函数不是很明白,求解答!
4 回复
readStream和writeStream一般来 说比较底层,其实也可以用比较高层的读文件方法
var fs = require(‘fs’); var buff = new Buffer(8); buff.writeUInt32BE(1111, 0); buff.writeFloatBE(3.14,4); fs.writeFile('data.bin’, buff,{encoding:’hex’}, function (err) { if (err) throw err; console.log(‘写入成功’); })
fs.readFile('data.bin’, { encodinig: ‘hex’ }, function (err, data) { if (err) throw err; console.log(data.readUInt32BE(0)); console.log(data.readFloatBE(4)); });