
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
The isstream npm package is a simple utility to check if an object is a stream. It provides functions to determine if an object is a readable, writable, or duplex stream.
Check if an object is a stream
This feature allows you to check if a given object is a stream. In this example, we use the fs module to create a readable stream and then check if it is a stream using isStream.
const isStream = require('isstream');
const fs = require('fs');
const readableStream = fs.createReadStream('example.txt');
console.log(isStream(readableStream)); // true
Check if an object is a readable stream
This feature allows you to check if a given object is a readable stream. In this example, we use the fs module to create a readable stream and then check if it is a readable stream using isStream.isReadable.
const isStream = require('isstream');
const fs = require('fs');
const readableStream = fs.createReadStream('example.txt');
console.log(isStream.isReadable(readableStream)); // true
Check if an object is a writable stream
This feature allows you to check if a given object is a writable stream. In this example, we use the fs module to create a writable stream and then check if it is a writable stream using isStream.isWritable.
const isStream = require('isstream');
const fs = require('fs');
const writableStream = fs.createWriteStream('example.txt');
console.log(isStream.isWritable(writableStream)); // true
Check if an object is a duplex stream
This feature allows you to check if a given object is a duplex stream. In this example, we create a duplex stream using the stream module and then check if it is a duplex stream using isStream.isDuplex.
const isStream = require('isstream');
const { Duplex } = require('stream');
const duplexStream = new Duplex();
console.log(isStream.isDuplex(duplexStream)); // true
The is-stream package provides similar functionality to isstream, allowing you to check if an object is a stream, readable stream, writable stream, or duplex stream. It is a lightweight and straightforward alternative.
The stream package is part of Node.js core and provides a comprehensive API for working with streams. While it does not provide simple type-checking functions like isstream, it offers extensive functionality for creating and managing streams.
The through2 package is a tiny wrapper around Node.js streams2 Transform to avoid explicit subclassing noise. It is more focused on stream transformation but can be used in conjunction with isstream for type-checking.
Test if an object is a Stream
The missing Stream.isStream(obj)
: determine if an object is standard Node.js Stream
. Works for Node-core Stream
objects (for 0.8, 0.10, 0.11, and in theory, older and newer versions) and all versions of readable-stream.
var isStream = require('isstream')
var Stream = require('stream')
isStream(new Stream()) // true
isStream({}) // false
isStream(new Stream.Readable()) // true
isStream(new Stream.Writable()) // true
isStream(new Stream.Duplex()) // true
isStream(new Stream.Transform()) // true
isStream(new Stream.PassThrough()) // true
You can also test for isReadable(obj)
, isWritable(obj)
and isDuplex(obj)
to test for implementations of Streams2 (and Streams3) base classes.
var isReadable = require('isstream').isReadable
var isWritable = require('isstream').isWritable
var isDuplex = require('isstream').isDuplex
var Stream = require('stream')
isReadable(new Stream()) // false
isWritable(new Stream()) // false
isDuplex(new Stream()) // false
isReadable(new Stream.Readable()) // true
isReadable(new Stream.Writable()) // false
isReadable(new Stream.Duplex()) // true
isReadable(new Stream.Transform()) // true
isReadable(new Stream.PassThrough()) // true
isWritable(new Stream.Readable()) // false
isWritable(new Stream.Writable()) // true
isWritable(new Stream.Duplex()) // true
isWritable(new Stream.Transform()) // true
isWritable(new Stream.PassThrough()) // true
isDuplex(new Stream.Readable()) // false
isDuplex(new Stream.Writable()) // false
isDuplex(new Stream.Duplex()) // true
isDuplex(new Stream.Transform()) // true
isDuplex(new Stream.PassThrough()) // true
Reminder: when implementing your own streams, please use readable-stream rather than core streams.
isStream is Copyright (c) 2015 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
FAQs
Determine if an object is a Stream
The npm package isstream receives a total of 15,895,935 weekly downloads. As such, isstream popularity was classified as popular.
We found that isstream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.