isstream.js 588 B

123456789101112131415161718192021222324252627
  1. var stream = require('stream')
  2. function isStream (obj) {
  3. return obj instanceof stream.Stream
  4. }
  5. function isReadable (obj) {
  6. return isStream(obj) && typeof obj._read == 'function' && typeof obj._readableState == 'object'
  7. }
  8. function isWritable (obj) {
  9. return isStream(obj) && typeof obj._write == 'function' && typeof obj._writableState == 'object'
  10. }
  11. function isDuplex (obj) {
  12. return isReadable(obj) && isWritable(obj)
  13. }
  14. module.exports = isStream
  15. module.exports.isReadable = isReadable
  16. module.exports.isWritable = isWritable
  17. module.exports.isDuplex = isDuplex