diff --git a/lib/svg-to-img.js b/lib/svg-to-img.js index dff94f9..7d7e975 100644 --- a/lib/svg-to-img.js +++ b/lib/svg-to-img.js @@ -20,13 +20,10 @@ module.exports = function (svg, format, out, cb) { .background(format === 'jpg' ? '#FFFFFF' : 'none') .flatten() .stream(format, function (err, stdout, stderr) { - if (err) { console.error(err); } - - stdout.on('end', function () { - imgCache.set(cacheIndex, [stdout]); - cb && cb(); - }); - + if (err) { console.error(err); return; } + var chunks = []; + stdout.on('data', function(chunk) { chunks.push(chunk); }); + stdout.on('end', function() { imgCache.set(cacheIndex, chunks); }); stdout.pipe(out); }); }; @@ -42,9 +39,9 @@ function DataStream(data) { util.inherits(DataStream, Readable); DataStream.prototype._read = function() { while (this.i < this.data.length) { - var stop = this.push(this.data[this.i]); + var keepPushing = this.push(this.data[this.i]); this.i++; - if (stop) { return; } + if (!keepPushing) { return; } } this.push(null); };