From 67bea21026c73e9d0871853fc5d1f3b5780dfc06 Mon Sep 17 00:00:00 2001 From: Dalibor Novak Date: Sun, 23 Nov 2014 20:16:36 +0000 Subject: [PATCH] Writable instead of through stream for partials As through stream used for partials never gets read, it blocks on 16 (highWaterMark) items. This means that plugin can't support more than 16 partials without change. --- index.js | 4 ++-- lib/writable.js | 30 ++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 lib/writable.js diff --git a/index.js b/index.js index 7508aa9..809d73a 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ var Handlebars = require('handlebars'); var Promise = require('bluebird'); var _ = require('lodash'); var Path = require('path'); +var writable = require('./lib/writable'); /** * Duck-typing to allow different promise implementations to work. @@ -26,10 +27,9 @@ function getNameFromPath(path) { function getPromiseFromPipe(pipe, fn) { var d = Promise.defer(); - pipe.pipe(through.obj(function (file, enc, cb) { + pipe.pipe(writable.obj(function (file, enc, cb) { var str = file.contents.toString(); fn(file, str); - this.push(file); cb(); }, function () { //end diff --git a/lib/writable.js b/lib/writable.js new file mode 100644 index 0000000..40bae75 --- /dev/null +++ b/lib/writable.js @@ -0,0 +1,30 @@ +var WritableStream = require('readable-stream/writable'); +var _ = require('lodash'); + +function writable(options, write, end) { + if (_.isFunction(options)) { + end = write; + write = options; + options = {}; + } + + var w = new WritableStream(options); + + w._write = write; + if (end) { + w.end = end; + } + + return w; +} + +module.exports = writable; +module.exports.obj = function obj(options, write, end) { + if (_.isFunction(options)) { + end = write; + write = options; + options = {}; + } + + return writable(_.defaults(options, { objectMode: true, highWaterMark: 16 }), write, end); +}; diff --git a/package.json b/package.json index 3619edf..484f6df 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "gulp-util": "^3.0.1", "handlebars": "^2.0.0", "lodash": "^2.4.1", + "readable-stream": "^1.0.33", "through2": "^0.6.2" }, "devDependencies": {