buffer.js 282 B

123456789101112131415
  1. var through = require('through2');
  2. module.exports = function(fn) {
  3. var buf = [];
  4. var end = function(cb) {
  5. this.push(buf);
  6. cb();
  7. if(fn) fn(null, buf);
  8. };
  9. var push = function(data, enc, cb) {
  10. buf.push(data);
  11. cb();
  12. };
  13. return through.obj(push, end);
  14. };