git ssb

0+

cel / pull-reverse



Commit c35743ecbec8f9c5790187a9d319e9e2ef622684

Initial commit

Charles Lehner committed on 3/6/2016, 11:11:30 PM

Files changed

README.mdadded
index.jsadded
package.jsonadded
test.jsadded
README.mdView
@@ -1,0 +1,22 @@
1 +# pull-reverse
2 +
3 +cache a pull-stream so it can be read in reverse
4 +
5 +```
6 +```
7 +
8 +## API
9 +
10 +```
11 +pull-reverse
12 +```
13 +
14 +## License
15 +
16 +Copyright (c) 2016 Charles Lehner
17 +
18 +Usage of the works is permitted provided that this instrument is
19 +retained with the works, so that any entity that uses the works is
20 +notified of this instrument.
21 +
22 +DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
index.jsView
@@ -1,0 +1,18 @@
1 +module.exports = function (read, onEnd) {
2 + var vals = []
3 +
4 + read(null, function next(end, data) {
5 + if (end) return onEnd && onEnd(end === true ? null : end)
6 + vals.push(data)
7 + read(null, next)
8 + })
9 +
10 + return function () {
11 + var i = vals.length - 1
12 + return function (end, cb) {
13 + if (end) cb()
14 + else if (i < 0) cb(true)
15 + else cb(null, vals[i--])
16 + }
17 + }
18 +}
package.jsonView
@@ -1,0 +1,22 @@
1 +{
2 + "name": "pull-reverse",
3 + "version": "0.0.0",
4 + "description": "cache a pull-stream so it can be read in reverse",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "tape test"
8 + },
9 + "repository": {
10 + "type": "git",
11 + "url": "https://github.com/clehner/pull-reverse"
12 + },
13 + "keywords": [
14 + "pull-stream"
15 + ],
16 + "author": "Charles Lehner (http://celehner.com/)",
17 + "license": "Fair",
18 + "devDependencies": {
19 + "pull-stream": "^3.2.0",
20 + "tape": "^4.5.0"
21 + }
22 +}
test.jsView
@@ -1,0 +1,18 @@
1 +var test = require('tape')
2 +var reverse = require('.')
3 +var pull = require('pull-stream')
4 +
5 +var vals = [1,2,3,4,5,4,'foo',null,Object()]
6 +
7 +test('reverse', function (t) {
8 + var reverseCache = reverse(pull.values(vals))
9 + t.test('1', doIt)
10 + t.test('2', doIt)
11 + function doIt(t) {
12 + pull(reverseCache(), pull.collect(function (err, values) {
13 + t.error(err, 'collect')
14 + t.deepEquals(values.reverse(), vals, 'values reverse')
15 + t.end()
16 + }))
17 + }
18 +})

Built with git-ssb-web