how to pass the data back from gulp.on('data') to the next step/pipe for eg. .pipe gulp.dest Here is a sample code in coffee
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)
Take a look at the Writing Plugins docs.
What you want is to create a transformation stream. Take a look at this Stream Handbook. In your case, you want to map
the stream and change it as it goes. The easiest way would be (in 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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With