From abd94a7f5a50f43c797a11b53549ae48fff667c3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 10 Oct 2016 03:43:44 +0200 Subject: add node_modules to address #4364 --- node_modules/gulp-stream/index.js | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 node_modules/gulp-stream/index.js (limited to 'node_modules/gulp-stream/index.js') diff --git a/node_modules/gulp-stream/index.js b/node_modules/gulp-stream/index.js new file mode 100644 index 000000000..5c3f1ece0 --- /dev/null +++ b/node_modules/gulp-stream/index.js @@ -0,0 +1,50 @@ +var through = require('through2'); +var Stream = require('stream'); + +// Consts +const PLUGIN_NAME = 'gulp-stream'; + +function gulpStream() { + var stream = through.obj(function(file, enc, callback) { + + // keep null files as-is + if (file.isNull()) { + this.push(file); + return callback(); + } + + // keep stream files as-is + if (file.isStream()) { + this.push(file); + return callback(); + } + + // transform buffer files into buffers + if (file.isBuffer()) { + var cstream = Readable(file.contents); + cstream.on('error', this.emit.bind(this, 'error')); + file.contents = cstream; + this.push(file); + return callback(); + } + + }); + + return stream; +}; + +function Readable(buffer){ + var readable = new Stream.Readable(); + var idx = 0; + readable._read = function(size) { + var chunk = buffer.slice(0, size); + buffer = buffer.slice(size); + var finished = (chunk.length == 0 && buffer.length == 0); + this.push(finished ? null : chunk); + }; + return readable; +} + + + +module.exports = gulpStream; -- cgit v1.2.3