aboutsummaryrefslogtreecommitdiff
path: root/node_modules/gulp-stream/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/gulp-stream/index.js')
-rw-r--r--node_modules/gulp-stream/index.js50
1 files changed, 50 insertions, 0 deletions
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;