Reputation: 24083
I am using node.js. I have a Buffer and I need to write it to a file named 'bla.js' and then pipe gulp's uglify. Something like:
var uglify = require('gulp-uglify');
var buffer = ....
var wstream = fs.createWriteStream('bla.js');
wstream.write(buffer);
wstream.pipe(uglify());
What is the correct way to do it?
Upvotes: 3
Views: 1485
Reputation: 1047
Looks like the plugin vinyl-source-stream provides a solution for what you want to do:
var source = require('vinyl-source-stream')
var streamify = require('gulp-streamify')
var browserify = require('browserify')
var fs = require('vinyl-fs');
var uglify = require('gulp-uglify');
var bundleStream = browserify('index.js').bundle()
bundleStream
.pipe(source('index.js'))
.pipe(streamify(uglify()))
.pipe(fs.dest('./bla.js'))
Upvotes: 1
Reputation: 10772
From what I can tell you should be able to call pipe()
on the readable stream more than once and have the contents sent to two different writable streams.
Eg (dry-coded):
var fs = require('fs')
, uglify = require('gulp-uglify');
var rstream = fs.createReadStream('test.log');
rstream.pipe(fs.createWriteStream('bla.js'));
rstream.pipe(uglify());
Upvotes: 1