Skip to content

Repository files navigation

isStream

Build Status

Test if an object is a Stream

NPM

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.

Usage:

varisStream=require('isstream')varStream=require('stream')isStream(newStream())// trueisStream({})// falseisStream(newStream.Readable())// trueisStream(newStream.Writable())// trueisStream(newStream.Duplex())// trueisStream(newStream.Transform())// trueisStream(newStream.PassThrough())// true

But wait! There's more!

You can also test for isReadable(obj), isWritable(obj) and isDuplex(obj) to test for implementations of Streams2 (and Streams3) base classes.

varisReadable=require('isstream').isReadablevarisWritable=require('isstream').isWritablevarisDuplex=require('isstream').isDuplexvarStream=require('stream')isReadable(newStream())// falseisWritable(newStream())// falseisDuplex(newStream())// falseisReadable(newStream.Readable())// trueisReadable(newStream.Writable())// falseisReadable(newStream.Duplex())// trueisReadable(newStream.Transform())// trueisReadable(newStream.PassThrough())// trueisWritable(newStream.Readable())// falseisWritable(newStream.Writable())// trueisWritable(newStream.Duplex())// trueisWritable(newStream.Transform())// trueisWritable(newStream.PassThrough())// trueisDuplex(newStream.Readable())// falseisDuplex(newStream.Writable())// falseisDuplex(newStream.Duplex())// trueisDuplex(newStream.Transform())// trueisDuplex(newStream.PassThrough())// true

Reminder: when implementing your own streams, please use readable-stream rather than core streams.

License

isStream is Copyright (c) 2015 Rod Vagg @rvagg and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.

About

Determine if an object is a Node.js Stream

Resources

Stars

63 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages