I think it would be better to throw in the following case. The following case also causes every newly created read stream to end immediately.
import fs from 'fs'
function length(rs){
return new Promise(res=>{
let a=[]
rs.on('data',[].push.bind(a))
rs.on('end',e=>{
res(Buffer.concat(a).length)
})
})
}
fs.writeFileSync('hello.txt','world')
;(async()=>{
// print 5 0 0
console.log(
await length(fs.createReadStream('hello.txt')),
await length(fs.createReadStream('hello.txt',{start:NaN,end:NaN})),
await length(fs.createReadStream('hello.txt')),
)
})()
I think it would be better to throw in the following case. The following case also causes every newly created read stream to end immediately.
$ node --experimental-modules a.mjswitha.mjs: