Skip to content

readline module and streams #16178

Closed
Closed
@Ginden

Description

@Ginden

Currently, readline module interface is rather special. Interface class is EventEmitter acting as stream, but not conforming to Stream interface. It's possible to redirect output to stream, but it's significantly less convenient than just .pipe.

Then I propose one of the following:

  • add class readline.Stream subclassing Transform.
    • readline.Interface can be backed by this stream, then no code duplication occurs. Though, I'm not sure about viability of this approach, as Interface contains lots of code related to TTY handling.
  • make readline.Interface instances subclasses of Transform stream

Compare:

foo = getReadableStream();
bar = transformStream();
foo
   .pipe(readline.Stream())
   .pipe(bar)
   .pipe(process.stdout)

vs.

foo = getReadableStream();
bar = transformStream();
readline.createInterface({
   input: foo,
   output: bar
}); // We are using factory function for side effects.
bar.pipe(process.stdout);

User-land packages providing this functionality:

  • byline (423k downloads per month)

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions