isStream
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.
Usage:
var isStream = require('isstream')
var Stream = require('stream')
isStream(new Stream())
isStream({})
isStream(new Stream.Readable())
isStream(new Stream.Writable())
isStream(new Stream.Duplex())
isStream(new Stream.Transform())
isStream(new Stream.PassThrough())
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.
var isReadable = require('isstream').isReadable
var isWritable = require('isstream').isWritable
var isDuplex = require('isstream').isDuplex
var Stream = require('stream')
isReadable(new Stream())
isWritable(new Stream())
isDuplex(new Stream())
isReadable(new Stream.Readable())
isReadable(new Stream.Writable())
isReadable(new Stream.Duplex())
isReadable(new Stream.Transform())
isReadable(new Stream.PassThrough())
isWritable(new Stream.Readable())
isWritable(new Stream.Writable())
isWritable(new Stream.Duplex())
isWritable(new Stream.Transform())
isWritable(new Stream.PassThrough())
isDuplex(new Stream.Readable())
isDuplex(new Stream.Writable())
isDuplex(new Stream.Duplex())
isDuplex(new Stream.Transform())
isDuplex(new Stream.PassThrough())
Reminder: when implementing your own streams, please use readable-stream rather than core streams.
License
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.