-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
58 lines (45 loc) · 941 Bytes
/
test.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
var tape = require('tape')
var timeStream = require('./')
var tempfile = require('tempfile')
var protoBuf = require('protocol-buffers')
var encoder = protoBuf(`
message Data {
required uint32 speed=1;
required uint32 neuron=2;
required uint32 distance=3;
}
`)
var object = [{
speed: 19,
neuron: 22,
distance: 31,
},
{
speed: 4,
neuron: 5,
distance: 6
},
{
speed: 7,
neuron: 8,
distance: 9
}
]
tape('encodes data to files', function (t) {
var filename = tempfile('test1')
var ts = timeStream.createWriteStream(filename, encoder.Data)
object.forEach(function (data) {
ts.write(data)
})
ts.end(function () {
var tsR = timeStream.createReadStream(filename, encoder.Data)
var array = []
tsR.on('data', function (data) {
array.push(data)
})
tsR.on('end', function () {
t.deepEquals(object, array)
t.end()
})
})
})