Giter Site home page Giter Site logo

isstream's Introduction

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:

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

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()) // 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.

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.

isstream's People

Contributors

rvagg avatar rossgammon avatar

Stargazers

 avatar Terence Hutton avatar Cat  avatar Norbert de Langen avatar JamesLinus avatar  avatar Glauber Mota avatar Rocco Musolino avatar Joshua Bartlett avatar Julien avatar Kreshnik Hasanaj avatar Adrian Perez avatar Vincenzo Ferrari avatar  avatar Tobias Goecke (Göcke) avatar coolhanddev avatar Luke Edwards avatar Frank Hsu avatar Rory Bradford avatar Michele Pangrazzi avatar César avatar Franco Correa avatar Gustavo Gard avatar Joe Harlow avatar Mohamed Meabed avatar Angus H. avatar Frank Hassanabad avatar João Sousa Andrade avatar Pablo Heredia avatar Jithin Shah avatar ZOU Bin avatar Keith Williams avatar Yosh avatar Sean Lang avatar waynedpj avatar Lalit Kapoor avatar Haoliang Gao avatar 平江 avatar Athan avatar Ellen Gummesson avatar Shawn Jonnet avatar Alberto Pose avatar  avatar Daniel Yang avatar Alexander Salas Bastidas avatar Cyrus David avatar Will O'Brien avatar Ryan avatar Ben Evans avatar Mathias Buus avatar Wang Qiu avatar Jonas Hermsmeier avatar Yiyu He avatar Feross Aboukhadijeh avatar Nicolas Gryman avatar Ron Waldon-Howe avatar Chris Talkington avatar 迁移到 leogiese avatar Hemanth HM avatar David Trejo avatar Sindre Sorhus avatar Po-Ying Chen avatar Mike Vegeto avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

isstream's Issues

Highlandjs

As highland is the main streaming Node.js framework, can you write in your docs, that isstream doesn't detect highland streams?

Doesn't actually work for Node-core Stream objects in 0.8

... because in Node 0.8 core streams, there are no _read or _write methods:

[~] nvm use 0.8
Now using node v0.8.28
[~] node
> require('isStream').isWritable(require('fs').createWriteStream('/tmp/foo'))
false
> require('isStream').isReadable(require('fs').createReadStream('/tmp/foo'))
false
> require('isStream').isDuplex(new (require('net').Socket)())
false
>
(^C again to quit)
>

[~] nvm use 0.10
Now using node v0.10.32
[~] node
> require('isStream').isWritable(require('fs').createWriteStream('/tmp/foo'))
true
> require('isStream').isReadable(require('fs').createReadStream('/tmp/foo'))
true
> require('isStream').isDuplex(new (require('net').Socket)())
true
>
(^C again to quit)
>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.