Welcome to the Linux Foundation Forum!

Output order is wrong in Stream chapter ?

phantomphantom Posts: 1
edited July 27 in LFW211 Class Forum

order element in output is not exactly :
'use strict'
const { Readable } = require('stream')
const createReadStream = () => {
const data = ['some', 'data', 'to', 'read']
return new Readable({
encoding: 'utf8',
read () {
if (data.length === 0) this.push(null)
else this.push(data.pop())
const readable = createReadStream()
readable.on('data', (data) => { console.log('got data', data) })
readable.on('end', () => { console.log('finished reading') })

It should be returned:
got data read
got data to
got data data
got data some
finished reading
because data.pop() will return an element from right to left of the array.


  • Hey @phantom well spotted, this is actually, this is an editing issue, the output is shown for this.push(data.shift()) but the code was not updated to that (and stayed as data.pop()). Thanks for letting us know!

Sign In or Register to comment.