pull-stream
Advanced tools
Comparing version 2.5.1 to 2.6.0
@@ -65,9 +65,13 @@ # Throughs | ||
## group (len) | ||
## group (length) | ||
chunk incoming data into arrays of max length `len`, | ||
(the last item may be shorter than len) | ||
Group incoming data into arrays of max length `length`, | ||
(the last item may be shorter than `length`) | ||
Useful for items you can handle in batches. | ||
Useful for data you can handle in batches. | ||
## flatten () | ||
Turn a stream of arrays into a stream of their items, (undoes group). | ||
## highWaterMark (n) | ||
@@ -74,0 +78,0 @@ |
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "2.5.1", | ||
"version": "2.6.0", | ||
"homepage": "https://github.com/dominictarr/pull-stream", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -27,1 +27,19 @@ var pull = require('../') | ||
}) | ||
require('tape')('flatten (ungroup)', function (t) { | ||
pull.count() | ||
.pipe(pull.take(20)) | ||
.pipe(pull.group(7)) | ||
.pipe(pull.group(3)) | ||
.pipe(pull.through(console.log)) | ||
.pipe(pull.flatten()) | ||
.pipe(pull.through(console.log)) | ||
.pipe(pull.flatten()) | ||
.pipe(pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.deepEqual(ary, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) | ||
t.end() | ||
})) | ||
}) | ||
@@ -137,2 +137,21 @@ function prop (map) { | ||
var flatten = exports.flatten = function (read) { | ||
var chunk | ||
return function (end, cb) { | ||
//this means that the upstream is sending an error. | ||
if(end) return read(ended = end, cb) | ||
if(chunk && chunk.length) | ||
return cb(null, chunk.shift()) | ||
read(null, function (err, data) { | ||
if(err) return cb(err) | ||
chunk = data | ||
if(chunk && chunk.length) | ||
return cb(null, chunk.shift()) | ||
}) | ||
} | ||
} | ||
var nextTick = process.nextTick | ||
@@ -139,0 +158,0 @@ |
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
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
28944
699