cli.js 943 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #! /usr/bin/env node
  2. 'use strict';
  3. var pkcs7 = require('./pkcs7');
  4. var fs = require('fs');
  5. var path = require('path');
  6. var userArgs = process.argv;
  7. if (userArgs.indexOf('-h') !== -1 || userArgs.indexOf('--help') !== -1) {
  8. console.log('usage: pkcs7');
  9. return console.log('pkcs7 expects input on stdin and outputs to stdout');
  10. }
  11. if (userArgs.indexOf('-v') !== -1 || userArgs.indexOf('--version') !== -1) {
  12. return console.log(JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'))).version);
  13. }
  14. var data = [];
  15. process.stdin.on('readable', function() {
  16. var chunk = process.stdin.read();
  17. if (chunk !== null) {
  18. data.push(chunk);
  19. }
  20. });
  21. process.stdin.on('end', function() {
  22. var buffer = Buffer.concat(data),
  23. bytes = new Uint8Array(buffer.length),
  24. i = buffer.length;
  25. while (i--) {
  26. bytes[i] = buffer[i];
  27. }
  28. // output the padded input
  29. process.stdout.write(new Buffer(pkcs7.pad(bytes)));
  30. });