-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkelvinadump.js
executable file
·78 lines (70 loc) · 2.62 KB
/
kelvinadump.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
/* Copyright 2017 Streampunk Media Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const H = require('highland');
const fs = require('fs');
const util = require('util');
const kelviniser = require('./pipelines/kelviniser.js');
const stripTheFiller = require('./pipelines/stripTheFiller.js');
const metatiser = require('./pipelines/metatiser.js');
const detailing = require('./pipelines/detailing.js');
const puppeteer = require('./pipelines/puppeteer.js');
var argv = require('yargs')
.help('help')
.default('metaclass', true)
.default('filler', false)
.default('detailing', true)
.default('nest', true)
.default('flatten', false)
.boolean(['filler', 'metaclass', 'detailing', 'nest', 'flatten'])
.string(['version'])
.usage('Dump an MXF file as a stream of JSON objects.\n' +
'Usage: $0 [options] <file.mxf>')
.describe('filler', 'include filler in the output')
.describe('metaclass', 'resolves keys to meta classes')
.describe('detailing', 'decode bytes to JS objects')
.describe('nest', 'nest children within preface')
.describe('flatten', 'show only detail for each KLV packet')
.example('$0 --filler my_big_camera_file.mxf')
.check((argv) => {
fs.accessSync(argv._[0], fs.R_OK);
return true;
})
.argv;
if (argv.filler) argv.metaclass = true;
if (argv.flatten) argv.detailing = true;
if (argv.nest) argv.detailing = true;
if (argv.detailing) argv.metaclass = true;
var klvs = H(fs.createReadStream(argv._[0])).through(kelviniser());
if (argv.metaclass) klvs = klvs.through(metatiser());
if (!argv.filler) klvs = klvs.through(stripTheFiller());
if (argv.detailing) klvs = klvs.through(detailing());
if (argv.nest) klvs = klvs.through(puppeteer());
klvs
.flatMap(x => {
if (argv.flatten) {
if (x.detail) {
return H([x.detail]);
}
if (x.ObjectClass === 'Preface') { // following on from puppeteer
return H([x]);
} else {
return H([]);
}
}
return H([x]);
})
.errors(e => { console.error(e); })
.each(klv => {
console.log(util.inspect(klv, { depth : null}));
})
.done(() => { console.log(`Completed dumping '${argv._[0]}'.`); });