Skip to content

isStream does not recognize standard Node.js Writable Streams (compatibility issue) #954

Description

@lyyffee

Problem

The current implementation of isStream in nodejsUtils.js is as follows:

isStream : function (obj) {
    return obj &&
        typeof obj.on === "function" &&
        typeof obj.pause === "function" &&
        typeof obj.resume === "function";
}

This implementation requires an object to have on, pause, and resume methods to be considered a stream. However, in Node.js, standard Writable Streams (such as those returned by fs.createWriteStream or HTTP response streams) do not have pause and resume methods—only Readable Streams do. As a result, the following code returns false when it should return true:

const fs = require('fs');
const ws = fs.createWriteStream('a.txt');
console.log(require('./lib/nodejsUtils').isStream(ws)); // returns false, expected true

Impact:

Standard Writable, Duplex, and Transform streams are not recognized as streams, which can break compatibility and expected behavior in Node.js environments.
This is inconsistent with community conventions and libraries such as is-stream, which use a more relaxed check.

Please consider updating this function for better compatibility. Thank you!

Activity

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

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions