pull-stream
Advanced tools
Comparing version 2.18.3 to 2.19.0
20
index.js
@@ -1,2 +0,1 @@ | ||
var sources = require('./sources') | ||
@@ -7,2 +6,21 @@ var sinks = require('./sinks') | ||
function isThrough (fun) { | ||
return fun.type === "Through" || fun.length === 1 | ||
} | ||
var exports = module.exports = function pull () { | ||
var args = [].slice.call(arguments) | ||
if(isThrough(args[0])) | ||
return function (read) { | ||
args.unshift(read) | ||
return pull.apply(null, args) | ||
} | ||
var read = args.shift() | ||
while(args.length) | ||
read = args.shift() (read) | ||
return read | ||
} | ||
for(var k in sources) | ||
@@ -9,0 +27,0 @@ exports[k] = u.Source(sources[k]) |
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "2.18.3", | ||
"version": "2.19.0", | ||
"homepage": "https://github.com/dominictarr/pull-stream", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -18,8 +18,11 @@ # pull-stream | ||
```js | ||
pull.values(['file1', 'file2', 'file3']) | ||
.pipe(pull.asyncMap(fs.stat)) | ||
.pipe(pull.collect(function (err, array) { | ||
console.log(array) | ||
}) | ||
pull( | ||
pull.values(['file1', 'file2', 'file3']) | ||
pull.asyncMap(fs.stat) | ||
pull.collect(function (err, array) { | ||
console.log(array) | ||
}) | ||
) | ||
``` | ||
note that `pull(a, b, c)` is basically the same as `a.pipe(b).pipe(c)`. | ||
@@ -60,3 +63,3 @@ The best thing about pull-stream is that it can be completely lazy. | ||
createSourceStream().pipe(createThroughStream()).pipe(createSinkStream()) | ||
pull(createSourceStream(), createThroughStream()), createSinkStream()) | ||
``` | ||
@@ -131,3 +134,3 @@ | ||
```js | ||
randomReadable().pipe(logger()) | ||
pull(randomReadable(), logger()) | ||
``` | ||
@@ -159,21 +162,15 @@ | ||
```js | ||
source.pipe(through).pipe(sink) | ||
pull(source, through, sink) | ||
``` | ||
When setting up pipeability, you must use the right | ||
function, so `pipe` has the right behavior. | ||
some times, it's simplest to describe a stream in terms of other streams. | ||
pull can detect what sort of stream it starts with (by counting arguments) | ||
and if you pull together through streams, it gives you a new through stream. | ||
Use `Source`, `Through` and `Sink`, | ||
to add pipeability to your pull-streams. | ||
## More Cool Stuff | ||
What if you could do this? | ||
```js | ||
var tripleThrough = | ||
through1().pipe(through2()).pipe(through3()) | ||
pull(through1(), through2(), through3()) | ||
//THE THREE THROUGHS BECOME ONE | ||
source().pipe(tripleThrough).pipe(sink()) | ||
pull(source(), tripleThrough, sink()) | ||
``` | ||
@@ -202,3 +199,3 @@ | ||
This should work: `a.pipe(x.pipe(y).pipe(z)).pipe(b)` | ||
Something like this should work: `a.pipe(x.pipe(y).pipe(z)).pipe(b)` | ||
this makes it possible to write a custom stream simply by | ||
@@ -205,0 +202,0 @@ combining a few available streams. |
@@ -5,13 +5,27 @@ var pull = require('../') | ||
pull.count() | ||
.pipe(pull.take(21)) | ||
.pipe(pull.asyncMap(function (data, cb) { | ||
return cb(null, data + 1) | ||
})) | ||
.pipe(pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.equal(ary.length, 21) | ||
t.end() | ||
})) | ||
// pull.count() | ||
// .pipe(pull.take(21)) | ||
// .pipe(pull.asyncMap(function (data, cb) { | ||
// return cb(null, data + 1) | ||
// })) | ||
// .pipe(pull.collect(function (err, ary) { | ||
// console.log(ary) | ||
// t.equal(ary.length, 21) | ||
// t.end() | ||
// })) | ||
pull( | ||
pull.count(), | ||
pull.take(21), | ||
pull.asyncMap(function (data, cb) { | ||
return cb(null, data + 1) | ||
}), | ||
pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.equal(ary.length, 21) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -22,21 +36,23 @@ | ||
var n = 0, m = 0, w = 6, i = 0 | ||
pull.count() | ||
.pipe(pull.take(21)) | ||
.pipe(pull.paraMap(function (data, cb) { | ||
console.log('>', i++) | ||
n ++ | ||
m = Math.max(m, n) | ||
setTimeout(function () { | ||
n -- | ||
pull( | ||
pull.count(), | ||
pull.take(21), | ||
pull.paraMap(function (data, cb) { | ||
console.log('>', i++) | ||
n ++ | ||
m = Math.max(m, n) | ||
setTimeout(function () { | ||
n -- | ||
console.log('<') | ||
cb(null, data + 1) | ||
}, Math.random() * 20) | ||
}, w)) | ||
.pipe(pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.equal(ary.length, 21) | ||
t.equal(m, w) | ||
t.end() | ||
})) | ||
console.log('<') | ||
cb(null, data + 1) | ||
}, Math.random() * 20) | ||
}, w), | ||
pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.equal(ary.length, 21) | ||
t.equal(m, w) | ||
t.end() | ||
}) | ||
) | ||
@@ -43,0 +59,0 @@ }) |
@@ -6,9 +6,11 @@ | ||
test('reduce becomes through', function (t) { | ||
pull.values([1,2,3]) | ||
.pipe(pull.reduce(function (a, b) {return a + b}, 0)) | ||
.pipe(pull.through(console.log)) | ||
.pipe(pull.collect(function (err, ary) { | ||
t.equal(ary[0], 6) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values([1,2,3]), | ||
pull.reduce(function (a, b) {return a + b}, 0), | ||
pull.through(console.log), | ||
pull.collect(function (err, ary) { | ||
t.equal(ary[0], 6) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -18,10 +20,15 @@ | ||
test('reduce becomes drain', function (t) { | ||
pull.values([1,2,3]) | ||
.pipe(pull.reduce(function (a, b) {return a + b}, 0, | ||
function (err, acc) { | ||
t.equal(acc, 6) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values([1,2,3]), | ||
pull.reduce( | ||
function (a, b) {return a + b}, | ||
0, | ||
function (err, acc) { | ||
t.equal(acc, 6) | ||
t.end() | ||
} | ||
) | ||
) | ||
}) | ||
@@ -6,9 +6,10 @@ | ||
test('filtered randomnes', function (t) { | ||
pull.infinite() | ||
.pipe(pull.filter(function (d) { | ||
pull( | ||
pull.infinite(), | ||
pull.filter(function (d) { | ||
console.log('f', d) | ||
return d > 0.5 | ||
})) | ||
.pipe(pull.take(100)) | ||
.pipe(pull.writeArray(function (err, array) { | ||
}), | ||
pull.take(100), | ||
pull.writeArray(function (err, array) { | ||
t.equal(array.length, 100) | ||
@@ -21,14 +22,15 @@ array.forEach(function (d) { | ||
t.end() | ||
})) | ||
}) | ||
) | ||
}) | ||
test('filter with regexp', function (t) { | ||
pull.infinite() | ||
.pipe(pull.map(function (d) { | ||
pull( | ||
pull.infinite(), | ||
pull.map(function (d) { | ||
return Math.round(d * 1000).toString(16) | ||
})) | ||
.pipe(pull.filter(/^[^e]+$/i)) //no E | ||
.pipe(pull.take(37)) | ||
.pipe(pull.writeArray(function (err, array) { | ||
}), | ||
pull.filter(/^[^e]+$/i), //no E | ||
pull.take(37), | ||
pull.writeArray(function (err, array) { | ||
t.equal(array.length, 37) | ||
@@ -40,3 +42,4 @@ console.log(array) | ||
t.end() | ||
})) | ||
}) | ||
) | ||
}) | ||
@@ -43,0 +46,0 @@ |
@@ -6,10 +6,12 @@ | ||
test('find 7', function (t) { | ||
pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
.pipe(pull.find(function (d) { | ||
return d == 7 | ||
}, function (err, seven) { | ||
t.equal(seven, 7) | ||
t.notOk(err) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), | ||
pull.find(function (d) { | ||
return d == 7 | ||
}, function (err, seven) { | ||
t.equal(seven, 7) | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -22,11 +24,12 @@ | ||
f.push(target) | ||
pull.values(f.sort()) | ||
.pipe(pull.find(function (d) { | ||
return d == target | ||
}, function (err, found) { | ||
t.equal(found, target) | ||
t.notOk(err) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values(f.sort()), | ||
pull.find(function (d) { | ||
return d == target | ||
}, function (err, found) { | ||
t.equal(found, target) | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -37,10 +40,12 @@ | ||
pull.values(f.sort()) | ||
.pipe(pull.find(function (d) { | ||
return d == target | ||
}, function (err, found) { | ||
t.equal(found, null) | ||
t.notOk(err) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values(f.sort()), | ||
pull.find(function (d) { | ||
return d == target | ||
}, function (err, found) { | ||
t.equal(found, null) | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -51,16 +56,18 @@ | ||
pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
.pipe(pull.asyncMap(function (e, cb) { | ||
process.nextTick(function () { | ||
cb(null, e) | ||
pull( | ||
pull.values([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), | ||
pull.asyncMap(function (e, cb) { | ||
process.nextTick(function () { | ||
cb(null, e) | ||
}) | ||
}), | ||
pull.find(function (d) { | ||
return d >= 7 | ||
}, function (err, seven) { | ||
t.equal(seven, 7) | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
})) | ||
.pipe(pull.find(function (d) { | ||
return d >= 7 | ||
}, function (err, seven) { | ||
t.equal(seven, 7) | ||
t.notOk(err) | ||
t.end() | ||
})) | ||
) | ||
}) |
@@ -5,14 +5,14 @@ var pull = require('../') | ||
test('flatten arrays', function (t) { | ||
pull.values([ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9] | ||
]) | ||
.pipe(pull.flatten()) | ||
.pipe(pull.collect(function (err, numbers) { | ||
t.deepEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], numbers) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values([ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9] | ||
]), | ||
pull.flatten(), | ||
pull.collect(function (err, numbers) { | ||
t.deepEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], numbers) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -22,12 +22,14 @@ | ||
pull.values([ | ||
pull.values([1, 2, 3]), | ||
pull.values([4, 5, 6]), | ||
pull.values([7, 8, 9]) | ||
]) | ||
.pipe(pull.flatten()) | ||
.pipe(pull.collect(function (err, numbers) { | ||
t.deepEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], numbers) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values([ | ||
pull.values([1, 2, 3]), | ||
pull.values([4, 5, 6]), | ||
pull.values([7, 8, 9]) | ||
]), | ||
pull.flatten(), | ||
pull.collect(function (err, numbers) { | ||
t.deepEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], numbers) | ||
t.end() | ||
}) | ||
) | ||
@@ -34,0 +36,0 @@ }) |
@@ -9,44 +9,48 @@ var pull = require('../') | ||
test('group', function (t) { | ||
pull.count() | ||
.pipe(pull.take(20)) | ||
.pipe(pull.group(7)) | ||
.pipe(pull.group(3)) | ||
.pipe(function (read) { | ||
return function (end, cb) { | ||
read(null, function (end, data) { | ||
if(!end) { | ||
t.deepEqual(data, [ | ||
[0, 1,2,3,4,5,6], | ||
[7,8,9,10,11,12,13], | ||
[14, 15,16,17,18,19] | ||
]) | ||
console.log(data) | ||
} | ||
pull( | ||
pull.count(), | ||
pull.take(20), | ||
pull.group(7), | ||
pull.group(3), | ||
function (read) { | ||
return function (end, cb) { | ||
read(null, function (end, data) { | ||
if(!end) { | ||
t.deepEqual(data, [ | ||
[0, 1,2,3,4,5,6], | ||
[7,8,9,10,11,12,13], | ||
[14, 15,16,17,18,19] | ||
]) | ||
console.log(data) | ||
} | ||
process.nextTick(cb.bind(null, end, data)) | ||
}) | ||
} | ||
}) | ||
.pipe(pull.drain(null, function (err) { | ||
t.notOk(err) | ||
t.end() | ||
})) | ||
process.nextTick(cb.bind(null, end, data)) | ||
}) | ||
} | ||
}, | ||
pull.drain(null, function (err) { | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
test('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) { | ||
t.notOk(err) | ||
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() | ||
})) | ||
pull( | ||
pull.count(), | ||
pull.take(20), | ||
pull.group(7), | ||
pull.group(3), | ||
pull.through(console.log), | ||
pull.flatten(), | ||
pull.through(console.log), | ||
pull.flatten(), | ||
pull.collect(function (err, ary) { | ||
t.notOk(err) | ||
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() | ||
}) | ||
) | ||
}) | ||
var pull = require('../') | ||
pull.values([1, 2, 3]) | ||
.pipe(pull.prepend(0)) | ||
.pipe(pull.collect(function (err, ary) { | ||
console.log(ary) | ||
})) | ||
pull( | ||
pull.values([1, 2, 3]), | ||
pull.prepend(0), | ||
pull.collect(function (err, ary) { | ||
console.log(ary) | ||
}) | ||
) |
@@ -1,5 +0,2 @@ | ||
var pull = require('../') | ||
var test = require('tape') | ||
@@ -27,16 +24,17 @@ | ||
pull.values(values) | ||
.pipe(pull.take(10)) | ||
.pipe(pull.through(null, function (err) { | ||
console.log('end') | ||
t.ok(true) | ||
process.nextTick(function () { | ||
t.end() | ||
pull( | ||
pull.values(values), | ||
pull.take(10), | ||
pull.through(null, function (err) { | ||
console.log('end') | ||
t.ok(true) | ||
process.nextTick(function () { | ||
t.end() | ||
}) | ||
}), | ||
pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.ok(true) | ||
}) | ||
})) | ||
.pipe(pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.ok(true) | ||
})) | ||
) | ||
}) | ||
@@ -46,8 +44,10 @@ | ||
test('take 5', function (t) { | ||
pull.values([1,2,3,4,5,6,7,8,9,10]) | ||
.pipe(pull.take(5)) | ||
.pipe(pull.collect(function (err, five) { | ||
t.deepEqual(five, [1,2,3,4,5]) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values([1,2,3,4,5,6,7,8,9,10]), | ||
pull.take(5), | ||
pull.collect(function (err, five) { | ||
t.deepEqual(five, [1,2,3,4,5]) | ||
t.end() | ||
}) | ||
) | ||
}) |
@@ -6,16 +6,17 @@ | ||
t.plan(2) | ||
pull.infinite() | ||
.pipe(pull.through(null, function (err) { | ||
console.log('end') | ||
t.ok(true) | ||
process.nextTick(function () { | ||
t.end() | ||
pull( | ||
pull.infinite(), | ||
pull.through(null, function (err) { | ||
console.log('end') | ||
t.ok(true) | ||
process.nextTick(function () { | ||
t.end() | ||
}) | ||
}), | ||
pull.take(10), | ||
pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.ok(true) | ||
}) | ||
})) | ||
.pipe(pull.take(10)) | ||
.pipe(pull.collect(function (err, ary) { | ||
console.log(ary) | ||
t.ok(true) | ||
})) | ||
) | ||
}) |
@@ -31,17 +31,19 @@ var pull = require('../') | ||
ls_r(start, pull.widthFirst) | ||
.pipe(pull.map(function (file) { | ||
pull( | ||
ls_r(start, pull.widthFirst), | ||
pull.map(function (file) { | ||
if(file === start) didStart = true | ||
return file.split('/').length | ||
})) | ||
.pipe(pull.filter(function (d) { | ||
}), | ||
pull.filter(function (d) { | ||
t.ok(d >= max) | ||
if(d > max) | ||
return max = d, true | ||
})) | ||
.pipe(pull.through(console.log)) | ||
.pipe(pull.drain(null, function () { | ||
}), | ||
pull.through(console.log), | ||
pull.drain(null, function () { | ||
t.ok(didStart) | ||
t.end() | ||
})) | ||
}) | ||
) | ||
}) | ||
@@ -53,4 +55,5 @@ | ||
//you have seen the dir already | ||
ls_r(start, pull.depthFirst) | ||
.pipe(pull.through(function (file) { | ||
pull( | ||
ls_r(start, pull.depthFirst), | ||
pull.through(function (file) { | ||
if(file != start) { | ||
@@ -62,6 +65,7 @@ var dir = path.dirname(file) | ||
seen[file] = true | ||
})) | ||
.pipe(pull.onEnd(function () { | ||
}), | ||
pull.onEnd(function () { | ||
t.end() | ||
})) | ||
}) | ||
) | ||
@@ -68,0 +72,0 @@ }) |
@@ -8,9 +8,10 @@ | ||
pull.values(numbers) | ||
.pipe(pull.unique()) | ||
.pipe(pull.collect(function (err, ary) { | ||
t.deepEqual(ary.sort(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values(numbers), | ||
pull.unique(), | ||
pull.collect(function (err, ary) { | ||
t.deepEqual(ary.sort(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | ||
t.end() | ||
}) | ||
) | ||
}) | ||
@@ -21,10 +22,12 @@ | ||
pull.values(numbers) | ||
.pipe(pull.nonUnique()) | ||
.pipe(pull.collect(function (err, ary) { | ||
t.deepEqual(ary.sort(), [0, 1, 2, 2, 3, 4, 6]) | ||
t.end() | ||
})) | ||
pull( | ||
pull.values(numbers), | ||
pull.nonUnique(), | ||
pull.collect(function (err, ary) { | ||
t.deepEqual(ary.sort(), [0, 1, 2, 2, 3, 4, 6]) | ||
t.end() | ||
}) | ||
) | ||
}) |
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
43121
30
1219
231