Skip to content

eos and stream type detection #29395

Description

@ronag

Looking at https://github.com/nodejs/node/blob/master/lib/internal/streams/end-of-stream.js#L31

It looks like "eos" uses the writable and readable properties to detect whether a stream is Readablelike or Writablelike. However, according my current incomplete understanding of these properties (#29377), they cannot/should not be used for this purpose, i.e. a Readable stream could in theory have a readable = false which later becomes a readable = true.

Should we maybe change these lines to something like e.g:

const isReadable = (
  typeof stream.readable === 'boolean' || 
  stream._readableState || 
  typeof stream.readableEnded === 'boolean'
);
let readable = opts.readable || (opts.readable !== false && isReadable);

Activity

  1. ronag commented on Sep 1, 2019

    @ronag
    MemberAuthor
  2. added
    streamIssues and PRs related to Node.js streams.
    on Sep 1, 2019
  3. mcollina commented on Sep 2, 2019

    @mcollina
    SponsorMember

    You are correct. You cannot desume if something is going to be readable/writable in the future by looking at those properties, only if it could be readable/writable now. I think we should improve eos in this regard.

  4. ronag commented on Sep 2, 2019

    @ronag
    MemberAuthor

    I think we can assume that is something a readable and is not destroyed it will become readable at some point.

    I think what we primarily need to improve is how we detect whether something is Writable or Readable, agree?

  5. ronag commented on Oct 6, 2019

    @ronag
    MemberAuthor

    This has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions