Skip to content

Stream 'readable' event oddness #198

@vsemozhetbyt

Description

@vsemozhetbyt
  • Version: 6.2.2
  • Platform: Windows 7 x64

The 'readable' event is emitted when there is data available to be read from the stream... The 'readable' event will also be emitted once the end of the stream data has been reached but before the 'end' event is emitted.

Why in this script (saved in UTF-8 with BOM) the handler is called no more and no less than twice?

/******************************************************************************/
'use strict';
/******************************************************************************/
const fs = require('fs');

const readStream = fs.createReadStream(__filename, { encoding: 'utf8' });

readStream.on('readable', () => {
  console.log(readStream.read(3));
});

The output:

 /*
***

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions