Comparing version 0.1.6 to 0.1.7
@@ -58,5 +58,4 @@ // Copyright 2014. A Medium Corporation | ||
var flush = function (cb) { | ||
this.push(cache) | ||
cb() | ||
var flush = function () { | ||
return cache | ||
} | ||
@@ -63,0 +62,0 @@ |
@@ -13,5 +13,5 @@ // Copyright 2014. A Medium Corporation | ||
* @param {Function} mapper | ||
* @param {Function=} flush | ||
* @param {Function=} flusher | ||
*/ | ||
function Mapper(mapper, flush) { | ||
function Mapper(mapper, flusher) { | ||
Transform.call(this, { | ||
@@ -25,5 +25,3 @@ objectMode: true, | ||
this.mapper = mapper | ||
if (flush) { | ||
this._flush = flush | ||
} | ||
this.flusher = flusher | ||
} | ||
@@ -41,2 +39,13 @@ util.inherits(Mapper, Transform) | ||
/** | ||
* @override | ||
*/ | ||
Mapper.prototype._flush = function (callback) { | ||
// If we don't have a flusher, bail. | ||
if (! this.flusher) return callback() | ||
var method = this.isAsync() ? '_asyncFlush' : '_syncFlush' | ||
this[method].call(this, callback) | ||
} | ||
/** | ||
* Apply a syncronous transformation. | ||
@@ -72,2 +81,28 @@ * @param {*} chunk | ||
/** | ||
* Synchronously flush the stream. | ||
* @param {Function} callback | ||
*/ | ||
Mapper.prototype._syncFlush = function (callback) { | ||
try { | ||
this.push(this.flusher()) | ||
callback() | ||
} catch (e) { | ||
callback(e) | ||
} | ||
} | ||
/** | ||
* Asynchronously flush the stream. | ||
* @param {Function} callback | ||
*/ | ||
Mapper.prototype._asyncFlush = function (callback) { | ||
this.flusher(function (err, data) { | ||
if (err) return callback(err) | ||
this.push(data) | ||
callback(null) | ||
}.bind(this)) | ||
} | ||
/** | ||
* Set the stream to be async. This is only relevant for map and filter streams, and not | ||
@@ -158,3 +193,7 @@ * for the built in streams that implement them. | ||
} else { | ||
return data.every(push.bind(this)) | ||
var needMoreData = false | ||
for (var i = 0; i < data.length; ++i) { | ||
needMoreData = push.call(this, data[i]) | ||
} | ||
return needMoreData | ||
} | ||
@@ -161,0 +200,0 @@ } |
@@ -23,5 +23,4 @@ // Copyright 2014. A Medium Corporation | ||
var flush = function (cb) { | ||
this.push([cache]) | ||
cb() | ||
var flush = function () { | ||
return [cache] | ||
} | ||
@@ -28,0 +27,0 @@ |
{ | ||
"name": "sculpt", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Generate Node 0.10-friendly transform streams to manipulate other streams.", | ||
@@ -16,8 +16,10 @@ "main": "index.js", | ||
"zuul": "bin/zuul-tests", | ||
"test": "npm run jshint && npm run jscs && npm run ensure-tests && npm run mocha && npm run zuul" | ||
"test": "bin/test" | ||
}, | ||
"devDependencies": { | ||
"es5-shim": "^4.0.3", | ||
"jscs": "~1.3.0", | ||
"jshint": "~2.4.4", | ||
"mocha": "~1.17.1", | ||
"phantomjs": "^1.9.10", | ||
"zuul": "^1.11.0" | ||
@@ -24,0 +26,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21733
6
16
438
1