index.js 518 B

12345678910111213141516171819202122232425262728
  1. var through2 = require('through2').obj
  2. var bl = require('bl')
  3. module.exports = vinylBuffer
  4. function vinylBuffer() {
  5. var stream = through2(write)
  6. return stream
  7. function write(file, _, next) {
  8. if (file.isNull()) return push(file, next)
  9. if (file.isBuffer()) return push(file, next)
  10. file.contents.pipe(bl(function(err, data) {
  11. if (err) return next(err)
  12. file.contents = data
  13. push(file, next)
  14. }))
  15. }
  16. function push(file, next) {
  17. stream.push(file)
  18. next()
  19. }
  20. }