index.js 514 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var stubs = require('stubs')
  3. /*
  4. * StreamEvents can be used 2 ways:
  5. *
  6. * 1:
  7. * function MyStream() {
  8. * require('stream-events').call(this)
  9. * }
  10. *
  11. * 2:
  12. * require('stream-events')(myStream)
  13. */
  14. function StreamEvents(stream) {
  15. stream = stream || this
  16. var cfg = {
  17. callthrough: true,
  18. calls: 1
  19. }
  20. stubs(stream, '_read', cfg, stream.emit.bind(stream, 'reading'))
  21. stubs(stream, '_write', cfg, stream.emit.bind(stream, 'writing'))
  22. return stream
  23. }
  24. module.exports = StreamEvents