-
Notifications
You must be signed in to change notification settings - Fork 75
/
create-write-stream.js
72 lines (59 loc) · 1.52 KB
/
create-write-stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'
var tape = require('tape')
var pull = require('pull-stream')
var ssbKeys = require('ssb-keys')
var createSSB = require('./util/create-ssb')
function run (opts = {}) {
var ssb = createSSB('test-ssb-write-stream')
var create = require('ssb-feed/util').create
tape('createWriteStream', function (t) {
var keys = ssbKeys.generate()
var prev
var init = prev = create(keys, 'init', { public: keys.public }, null)
var q = [init]
var l = 5
while (l--) {
q.push(prev = create(keys, 'msg', { count: l }, prev))
}
pull(
pull.values(q),
pull.asyncMap(function (data, cb) {
setTimeout(function () {
cb(null, data)
}, ~~(Math.random() * 500))
}),
ssb.createWriteStream(function (err) {
t.error(err)
t.end()
})
)
})
tape('createWriteStream (overwrite)', function (t) {
var keys = ssbKeys.generate()
var prev
var init = prev = create(keys, 'init', { public: keys.public }, null)
var q = [init]
var l = 5
while (l--) {
q.push(prev = create(keys, 'msg', { count: l }, prev))
}
q.push(q[3])
q.push(q[4])
pull(
pull.values(q),
pull.asyncMap(function (data, cb) {
setTimeout(function () {
cb(null, data)
}, ~~(Math.random() * 500))
}),
ssb.createWriteStream(function (err) {
t.error(err)
ssb.close(err => {
t.error(err, 'ssb.close - createWriteStream')
t.end()
})
})
)
})
}
run()