git ssb

1+

Dominic / secure-scuttlebutt



Tree: 6dde1c5e1d32a7427848bfad8a4641577bd0d1ab

Files: 6dde1c5e1d32a7427848bfad8a4641577bd0d1ab / test / write-stream.js

1692 bytesRaw
1'use strict'
2var tape = require('tape')
3var level = require('level-test')()
4var sublevel = require('level-sublevel/bytewise')
5var pull = require('pull-stream')
6var ssbKeys = require('ssb-keys')
7
8
9module.exports = function (opts) {
10 var db = sublevel(level('test-ssb-feed', {
11 valueEncoding: require('../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
83if(!module.parent)
84 module.exports(require('../defaults'))
85
86

Built with git-ssb-web