Files: 113223327508da436eab9a15c25935b6e5e18258 / test / write-stream.js
1683 bytesRaw
1 | |
2 | var tape = require('tape') |
3 | var level = require('level-test')() |
4 | var sublevel = require('level-sublevel/bytewise') |
5 | var pull = require('pull-stream') |
6 | var ssbKeys = require('ssb-keys') |
7 | |
8 | |
9 | module.exports = function (opts) { |
10 | var db = sublevel(level('test-ssb-feed', { |
11 | valueEncoding: opts.codec |
12 | })) |
13 | |
14 | var ssb = require('../')(db, opts) |
15 | |
16 | var create = require('ssb-feed/util').create |
17 | |
18 | tape('write-stream', function (t) { |
19 | var keys = ssbKeys.generate() |
20 | |
21 | var prev |
22 | var init = prev = create(keys, 'init', {public: keys.public}, null) |
23 | var q = [init] |
24 | |
25 | var l = 5 |
26 | while(l--) { |
27 | q.push(prev = create(keys, 'msg', {count: l}, prev)) |
28 | } |
29 | |
30 | console.log(q) |
31 | |
32 | pull( |
33 | pull.values(q), |
34 | pull.asyncMap(function (data, cb) { |
35 | setTimeout(function () { |
36 | cb(null, data) |
37 | }, ~~(Math.random()*500)) |
38 | }), |
39 | ssb.createWriteStream(function (err) { |
40 | if(err) throw err |
41 | t.end() |
42 | }) |
43 | ) |
44 | |
45 | }) |
46 | |
47 | tape('write-stream, overwrite', function (t) { |
48 | |
49 | var keys = ssbKeys.generate() |
50 | |
51 | var prev |
52 | var init = prev = create(keys, 'init', {public: keys.public}, null) |
53 | var q = [init] |
54 | |
55 | var l = 5 |
56 | while(l--) { |
57 | q.push(prev = create(keys, 'msg', {count: l}, prev)) |
58 | } |
59 | |
60 | q.push(q[3]) |
61 | q.push(q[4]) |
62 | |
63 | console.log(q) |
64 | |
65 | pull( |
66 | pull.values(q), |
67 | pull.asyncMap(function (data, cb) { |
68 | setTimeout(function () { |
69 | cb(null, data) |
70 | }, ~~(Math.random()*500)) |
71 | }), |
72 | ssb.createWriteStream(function (err) { |
73 | if(err) throw err |
74 | t.end() |
75 | }) |
76 | ) |
77 | |
78 | }) |
79 | |
80 | |
81 | } |
82 | |
83 | if(!module.parent) |
84 | module.exports(require('../defaults')) |
85 | |
86 |
Built with git-ssb-web