- Version: 6.4.0
- Platform: Ubuntu 14.04 x64
- Subsystem: fs
After reading from position 0 (using fs.read), subsequence read with position null reads the incorrect data.
I would expect a read from position 0 followed by a read from null position to read from the next set of data per the documentation:
position is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.
Save the following to a file and run it.
constfs=require('fs');constassert=require('assert');// change this to toggle failing vs passing behaviorconstfail=true;fs.open(__filename,'r',(err,fd)=>{assert(!err);constbuff=newBuffer(4);// this is the line that causes incorrect (unexpected?) behavior// if 0 is passed to read, then the subsequent read with 'null'// results in the wrong data being read// when `null` is used I get `cons` followed by `t fs`// when 0 is used first, I get `cons` followed by `cons`fs.read(fd,buff,0,4,(fail) ? 0 : null,(err,bytes,buffer)=>{assert(!err);assert.equal(buffer.toString(),'cons');console.log(buffer.toString());fs.read(fd,buff,0,4,null,(err,bytes,buffer)=>{assert(!err);assert.equal(buffer.toString(),'t fs');console.log(buffer.toString());});});});
After reading from position
0(using fs.read), subsequence read with positionnullreads the incorrect data.I would expect a read from position 0 followed by a read from null position to read from the next set of data per the documentation:
Save the following to a file and run it.