-
Notifications
You must be signed in to change notification settings - Fork 62
/
checker.js
34 lines (26 loc) · 1.13 KB
/
checker.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
if(process.argv.length < 5){
console.log('Usage: node checker.js <formatYaml> <inputBinary> <checkJson>');
return;
}
var yamlFn = process.argv[2];
var inputFn = process.argv[3];
var checkJsonFn = process.argv[4];
var fs = require("fs");
require('./lib/kaitai/kaitai-struct-compiler-fastopt.js');
var YAML = require('./lib/kaitai/yaml_practice.js');
var KaitaiStream = require('./lib/_npm/kaitai-struct/KaitaiStream.js');
var requireFromString = require('./lib/require-from-string/require-from-string.js');
var practiceModeChecker = require('./js/practiceModeChecker.js');
var ks = io.kaitai.struct.MainJs();
var srcYaml = fs.readFileSync(yamlFn, 'utf8');
var src = YAML.parse(srcYaml);
var compiled = ks.compile('javascript', src, false)[0];
var root = requireFromString(compiled);
var inputData = fs.readFileSync(inputFn);
var inputStream = new KaitaiStream(inputData);
var parsed = new root(inputStream);
var checkJson = JSON.parse(fs.readFileSync(checkJsonFn, 'utf8'));
//console.log(parsed);
//console.log(checkJson);
var checkResult = practiceModeChecker(parsed, checkJson);
console.log(JSON.stringify({success: checkResult.allMatch}));