You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using a fs.ReadStream from fs.createReadStream() using no encoding:
fs.ReadStream.bytesRead appears (from my own testing) to reflect the total number of bytes read from the system, into the internal buffer, where I was erroneously using it to track the total number of bytes returned from read() calls. My code worked like this:
while(stream.bytesRead<endIndex){constdata=stream.read(Math.min(blockSize,endIndex-stream.bytesRead));if(data==null){awaitsleep(50);continue;}// process data}
The problem I was running into was that stream.bytesRead was only being updated during the sleep time, so when the stream reached endIndex while the script was waiting for data, the loop would exit early, and the last chunk would be skipped. I wrote the loop this way with the wrong assumption that bytesRead reflected the total number of bytes returned from read() calls, but I can understand that it represents bytes read from the system.
Activity
avivkeller commentedon Jul 29, 2026
@nodejs/fs
Archkon commentedon Aug 8, 2026