git ssb

0+

mixmix / flume-intro



Commit 612fe50d680268eabc44b1146954eb2bff79eb31

files from live stream

mix irving committed on 1/11/2018, 6:24:39 AM
Parent: 2752ba462686c9703b6da041f964ba38bb085f5d

Files changed

.gitignorechanged
package.jsonchanged
1_write_to_flume.jsadded
2_read_from_flume.jsadded
3_read_flume_live.jsadded
4_flume_view.jsadded
5_flume_view_reading.jsadded
6_flume_view_reading_source.jsadded
.gitignoreView
@@ -1,3 +1,5 @@
11 flumelog
22 package-lock.json
33 node_modules
4 +demo_log
5 +stats.json
package.jsonView
@@ -15,6 +15,13 @@
1515 "license": "ISC",
1616 "bugs": {
1717 "url": "https://github.com/mixmix/flume-intro/issues"
1818 },
19- "homepage": "https://github.com/mixmix/flume-intro#readme"
19 + "homepage": "https://github.com/mixmix/flume-intro#readme",
20 + "dependencies": {
21 + "flumecodec": "0.0.1",
22 + "flumedb": "^0.4.6",
23 + "flumelog-offset": "^3.2.6",
24 + "flumeview-reduce": "^1.3.12",
25 + "pull-stream": "^3.6.1"
26 + }
2027 }
1_write_to_flume.jsView
@@ -1,0 +1,14 @@
1 +const Flume = require('flumedb')
2 +const FlumeLog = require('flumelog-offset')
3 +const codec = require('flumecodec')
4 +const FlumeView = require('flumeview-reduce')
5 +
6 +const log = FlumeLog('demo_log', { codec: codec.json })
7 +const db = Flume(log)
8 +
9 +
10 +db.append({ message: 'hi scuttlers' }, (err, data) => {
11 + if (err) throw err
12 +
13 + console.log(data)
14 +})
2_read_from_flume.jsView
@@ -1,0 +1,21 @@
1 +const Flume = require('flumedb')
2 +const FlumeLog = require('flumelog-offset')
3 +const codec = require('flumecodec')
4 +const FlumeView = require('flumeview-reduce')
5 +
6 +const pull = require('pull-stream')
7 +
8 +const log = FlumeLog('demo_log', { codec: codec.json })
9 +const db = Flume(log)
10 +
11 +db.get(62, console.log)
12 +
13 +pull(
14 + db.stream(), // source
15 + pull.map(msg => msg.value.message),
16 + pull.drain(msg => { // sink
17 + console.log(msg)
18 + })
19 +)
20 +
21 +
3_read_flume_live.jsView
@@ -1,0 +1,35 @@
1 +var Flume = require('flumedb')
2 +var FlumeLog = require('flumelog-offset')
3 +var codec = require('flumecodec')
4 +var pull = require('pull-stream')
5 +var path = require('path')
6 +
7 +const log = FlumeLog('demo_log', { codec: codec.json })
8 +
9 +var db = Flume(log)
10 +
11 +pull(
12 + db.stream({ live: true }),
13 + pull.drain(
14 + viewState => {
15 + console.log('FlumeDB.stream:', viewState)
16 + console.log()
17 + },
18 + () => console.log('DONE: db stream')
19 + )
20 +)
21 +
22 +pull(
23 + pull.values([1,2,3,4,5,6,7]),
24 + pull.asyncMap((val, cb) => setTimeout(
25 + () => cb(null, val),
26 + 500
27 + )),
28 + pull.drain(
29 + val => db.append({ count: val }, (err, seq) => {
30 + console.log(`FlumeDB.append: appended '${val}' at offset of ${seq} bytes`)
31 + console.log()
32 + }),
33 + () => console.log('DONE: append stream')
34 + )
35 +)
4_flume_view.jsView
@@ -1,0 +1,45 @@
1 +var Flume = require('flumedb')
2 +var FlumeLog = require('flumelog-offset')
3 +var codec = require('flumecodec')
4 +var pull = require('pull-stream')
5 +
6 +var FlumeView = require('flumeview-reduce')
7 +
8 +var log = FlumeLog('demo_log', { codec: codec.json })
9 +
10 +var db = Flume(log)
11 + .use('stats', FlumeView(
12 + 2, //version
13 + (acc, val) => { // reducer,
14 + console.log('+')
15 + return {
16 + sum: acc.sum + val,
17 + squareSum: acc.squareSum + val*val
18 + }
19 + },
20 + (msg) => msg.count, // map,
21 + null, // codec
22 + {
23 + sum: 0,
24 + squareSum: 0
25 + } //initial
26 + ))
27 + // .use('someOtherView', otherView)
28 +
29 +
30 +// writing pull-stream
31 +pull(
32 + pull.values([1,2,3,4,5,6,7]),
33 + pull.asyncMap((val, cb) => setTimeout(
34 + () => cb(null, val),
35 + 500
36 + )),
37 + pull.drain(
38 + val => db.append({ count: val }, (err, seq) => {
39 + console.log(`FlumeDB.append: appended '${val}' at offset of ${seq} bytes`)
40 + console.log()
41 + }),
42 + () => console.log('DONE: append stream')
43 + )
44 +)
45 +
5_flume_view_reading.jsView
@@ -1,0 +1,46 @@
1 +var Flume = require('flumedb')
2 +var FlumeLog = require('flumelog-offset')
3 +var codec = require('flumecodec')
4 +var pull = require('pull-stream')
5 +
6 +var FlumeView = require('flumeview-reduce')
7 +
8 +var log = FlumeLog('demo_log', { codec: codec.json })
9 +
10 +var db = Flume(log)
11 + .use('stats', FlumeView(
12 + 2, //version
13 + (acc, val) => { // reducer,
14 + console.log('+')
15 + return {
16 + sum: acc.sum + val,
17 + squareSum: acc.squareSum + val*val
18 + }
19 + },
20 + (msg) => msg.count, // map,
21 + null, // codec
22 + {
23 + sum: 0,
24 + squareSum: 0
25 + } //initial
26 + ))
27 + // .use('someOtherView', otherView)
28 +
29 +// writing pull-stream
30 +pull(
31 + pull.values([1,2,3,4,5,6,7]),
32 + pull.asyncMap((val, cb) => setTimeout(
33 + () => cb(null, val),
34 + 500
35 + )),
36 + pull.drain(
37 + val => db.append({ count: val }, (err, seq) => {
38 + console.log(`FlumeDB.append: appended '${val}' at offset of ${seq} bytes`)
39 + db.stats.get((err, val) => console.log('the view state:', err, val))
40 + }),
41 + () => {
42 + console.log('DONE: append stream')
43 + }
44 + )
45 +)
46 +
6_flume_view_reading_source.jsView
@@ -1,0 +1,57 @@
1 +var Flume = require('flumedb')
2 +var FlumeLog = require('flumelog-offset')
3 +var codec = require('flumecodec')
4 +var pull = require('pull-stream')
5 +
6 +var FlumeView = require('flumeview-reduce')
7 +
8 +var log = FlumeLog('demo_log', { codec: codec.json })
9 +
10 +var db = Flume(log)
11 + .use('stats', FlumeView(
12 + 2, //version
13 + reducer,
14 + (msg) => msg.count, // map,
15 + null, // codec
16 + {
17 + sum: 0,
18 + squareSum: 0
19 + } //initial
20 + ))
21 + // .use('someOtherView', otherView)
22 +
23 +function reducer (acc, val) { // reducer,
24 + console.log('+')
25 + return {
26 + sum: acc.sum + val,
27 + squareSum: acc.squareSum + val*val
28 + }
29 +}
30 +
31 +var viewState
32 +pull(
33 + db.stats.stream({live: true}),
34 + pull.drain(val => {
35 + if (!viewState) viewState = val
36 + else viewState = reducer(viewState, val)
37 + console.log(viewState)
38 + })
39 +)
40 +
41 +// writing pull-stream
42 +pull(
43 + pull.values([1,2,3,4,5,6,7]),
44 + pull.asyncMap((val, cb) => setTimeout(
45 + () => cb(null, val),
46 + 500
47 + )),
48 + pull.drain(
49 + val => db.append({ count: val }, (err, seq) => {
50 + console.log(`FlumeDB.append: appended '${val}' at offset of ${seq} bytes`)
51 + }),
52 + () => {
53 + console.log('DONE: append stream')
54 + }
55 + )
56 +)
57 +

Built with git-ssb-web