forked from deoxxa/dissolve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-loop.js
More file actions
executable file
·41 lines (33 loc) · 784 Bytes
/
Copy pathexample-loop.js
File metadata and controls
executable file
·41 lines (33 loc) · 784 Bytes
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
#!/usr/bin/env node
var Dissolve = require("./index");
var parser = Dissolve().tap(function() {
var data_i = 0;
this.uint8("data_count").loop("data", function(end) {
if (data_i++ === this.vars.data_count) {
return end(true);
}
var elements_i = 0;
this.uint8("element_count").loop("elements", function(end) {
if (elements_i++ === this.vars.element_count) {
return end(true);
}
this.uint8("element");
});
}).tap(function() {
this.push(this.vars);
this.vars = Object.create(null);
});
});
parser.on("readable", function() {
var e;
while (e = parser.read()) {
console.log(JSON.stringify(e, null, 2));
}
});
parser.write(new Buffer([
0x02,
0x02,
0x01, 0x02,
0x02,
0x03, 0x04,
]));