cli.js
1.06 KB
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
#! /usr/bin/env node
'use strict';
const pkcs7 = require('../dist/pkcs7.cjs.js');
const fs = require('fs');
const path = require('path');
const userArgs = process.argv;
if (userArgs.indexOf('-h') !== -1 || userArgs.indexOf('--help') !== -1) {
// eslint-disable-next-line
console.log('usage: pkcs7');
// eslint-disable-next-line
console.log('pkcs7 expects input on stdin and outputs to stdout');
process.exit();
}
if (userArgs.indexOf('-v') !== -1 || userArgs.indexOf('--version') !== -1) {
// eslint-disable-next-line
console.log(JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'))).version);
process.exit();
}
const data = [];
process.stdin.on('readable', function() {
const chunk = process.stdin.read();
if (chunk !== null) {
data.push(chunk);
}
});
process.stdin.on('end', function() {
const buffer = Buffer.concat(data);
const bytes = new Uint8Array(buffer.length);
let i = buffer.length;
while (i--) {
bytes[i] = buffer[i];
}
// output the padded input
process.stdout.write(new Buffer(pkcs7.pad(bytes)));
});