Подтвердить что ты не робот

Gulp.on('data') Как передать данные в следующий канал

как передать данные обратно из gulp.on('data') на следующий шаг/канал, например..pipe gulp.dest Вот пример кода в кофе

gulp.src(src)
    .on 'data',->
            # make change to file object
            # pass back the changed file object ?? how to pass it back to the next stream
    .pipe gulp.dest(dest)
4b9b3361

Ответ 1

Взгляните на Документы плагинов для вложений.

Вы хотите создать поток преобразования. Взгляните на этот Справочник по потокам. В вашем случае вы хотите map поток и изменить его по мере его поступления. Самый простой способ - (в JS):

gulp.src(src)
  .pipe(makeChange())
  .pipe(gulp.dest(dest));

function makeChange() {
  // you're going to receive Vinyl files as chunks
  function transform(file, cb) {
    // read and modify file contents
    file.contents = new Buffer(String(file.contents) + ' some modified content');

    // if there was some error, just pass as the first parameter here
    cb(null, file);
  }

  // returning the map will cause your transform function to be called
  // for each one of the chunks (files) you receive. And when this stream
  // receives a 'end' signal, it will end as well.
  // 
  // Additionally, you want to require the `event-stream` somewhere else.
  return require('event-stream').map(transform);
}