git ssb

0+

Dominic / ssb-validate



Tree: 5c49f6009ad5b21074c77817ed53d140a4b0f9b6

Files: 5c49f6009ad5b21074c77817ed53d140a4b0f9b6 / dump.js

1705 bytesRaw
1var validate = require('./')
2var pull = require('pull-stream')
3var state = validate.initial()
4
5var Log = require('flumelog-offset')
6
7var logfile = '/tmp/ssb-validate_dump-test'
8try { require('fs').unlinkSync(logfile) } catch (_) {}
9
10var log = Log(logfile, 1024, require('flumecodec/json'))
11
12var async = require('./async')(state, log)
13
14require('ssb-client')(function (err, sbot) {
15 var c = 0, _c = 0, e = 0, d = 0, q = 0, v = 0, ts = Date.now(), start = Date.now()
16
17 console.log('c, _c, d, e, q, v, c/s, mb, mb/s, s')
18
19 function ConsoleLog () {
20 var s = (ts - start)/1000
21 var mb = log.since.value / (1024*1024)
22 console.log(c, c - _c, d, e, q, v, c / s, mb, mb/s, s)
23 _c = c
24 d = 0
25
26 }
27
28 function maybeLog () {
29 if(Date.now() > ts + 1000) {
30 ConsoleLog()
31 ts = Date.now()
32 }
33 }
34
35 var author = null
36
37 pull(
38 sbot.createLogStream({}),
39 function (read) {
40 return function (abort, cb) {
41 read(abort, function next (err, data) {
42 q = async.queued()
43 v = async.validated()
44 c = q + v
45 if(err) {
46 ConsoleLog()
47 return async.flush(true, function (_) {
48 q = async.queued()
49 v = async.validated()
50 c = q + v
51 ConsoleLog()
52 cb(err)
53 })
54 }
55 maybeLog()
56 async.queue(data.value)
57 if(state.queue.length > 100) {
58 async.flush(null, function (err, data) {
59 maybeLog()
60 cb(err, data)
61 })
62 }
63 else
64 read(null, next)
65 })
66 }
67 },
68 pull.drain(null, function () {
69 sbot.close()
70 })
71 )
72})
73
74
75
76
77

Built with git-ssb-web