index.js 550 B

12345678910111213141516171819202122232425262728293031323334
  1. var Writable = require('stream').Writable;
  2. var inherits = require('util').inherits;
  3. module.exports = resumer;
  4. function resumer(stream) {
  5. if (!stream.readable) {
  6. return stream;
  7. }
  8. if (stream._read) {
  9. stream.pipe(new Sink);
  10. return stream;
  11. }
  12. if (typeof stream.resume === 'function') {
  13. stream.resume();
  14. return stream;
  15. }
  16. return stream;
  17. }
  18. function Sink() {
  19. Writable.call(this, {
  20. objectMode: true
  21. });
  22. }
  23. inherits(Sink, Writable);
  24. Sink.prototype._write = function(chunk, encoding, cb) {
  25. setImmediate(cb);
  26. };