You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
595 B

  1. module.exports = function(obj){
  2. var onData
  3. , onEnd
  4. , events = [];
  5. // buffer data
  6. obj.on('data', onData = function(data, encoding){
  7. events.push(['data', data, encoding]);
  8. });
  9. // buffer end
  10. obj.on('end', onEnd = function(data, encoding){
  11. events.push(['end', data, encoding]);
  12. });
  13. return {
  14. end: function(){
  15. obj.removeListener('data', onData);
  16. obj.removeListener('end', onEnd);
  17. },
  18. resume: function(){
  19. this.end();
  20. for (var i = 0, len = events.length; i < len; ++i) {
  21. obj.emit.apply(obj, events[i]);
  22. }
  23. }
  24. };
  25. };