Skip to content

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

@lyyffee

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions