Is it possible to convert stream to buffer synchronously?

739 Views Asked by At

Look at the simplest Gulp task that uses gulp-tap:

var gulp = require('gulp');
var tap = require('gulp-tap');    

gulp.task('mytask', function () {
    return gulp.src("src/*/*.js")
        .pipe(tap(function (file) {
            file.contents = new Buffer('blabla');        
        }))
    .pipe(gulp.dest('./dist'));
});

It takes files from the src directory, replaces content with "blabla" and saves those "spoiled" files to the "dist" directory. It's easy!

But what if we have stream instead of the "blabla"? For example:

var gulp = require('gulp');
var tap = require('gulp-tap');
var jsdocParse= require("jsdoc-parse");  

gulp.task('jsdoc', function () {
  return gulp.src("src/*/*.js")
    .pipe(tap(function (file) {
      var stream = jsdocParse(file.path);
      file.contents = ???;
    }))
    .pipe(gulp.dest('./dist'));
});
1

There are 1 best solutions below

0
On BEST ANSWER

Try this:

gulp.task('mytask', function () {
    return gulp.src("src/*.js")
        .pipe(tap(function (file, t) {
          file.contents = Buffer.concat([
                jsdocParse(file.path)
            ]);
        }))
    .pipe(gulp.dest('./dist'));
});