Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

crc32.njs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env node
  2. /* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
  3. /* eslint-env node */
  4. /* vim: set ts=2 ft=javascript: */
  5. /*jshint node:true */
  6. var X/*:CRC32Module*/;
  7. try { X = require('../'); } catch(e) { X = require('crc-32'); }
  8. function help()/*:number*/ {
  9. [
  10. "usage: crc32 [options] [filename]",
  11. "",
  12. "Options:",
  13. " -h, --help output usage information",
  14. " -V, --version output the version number",
  15. " -S, --seed=<n> use integer seed as starting value (rolling CRC)",
  16. " -H, --hex-seed=<h> use hex seed as starting value (rolling CRC)",
  17. " -d, --signed print result with format `%d` (default)",
  18. " -u, --unsigned print result with format `%u`",
  19. " -x, --hex print result with format `%0.8x`",
  20. " -X, --HEX print result with format `%0.8X`",
  21. " -F, --format=<s> use specified printf format",
  22. "",
  23. "Set filename = '-' or pipe data into crc32 to read from stdin",
  24. "Default output mode is signed (-d)",
  25. ""
  26. ].forEach(function(l) { console.log(l); });
  27. return 0;
  28. }
  29. function version()/*:number*/ { console.log(X.version); return 0; }
  30. var fs = require('fs');
  31. require('exit-on-epipe');
  32. function die(msg/*:string*/, ec/*:?number*/)/*:void*/ { console.error(msg); process.exit(ec || 0); }
  33. var args/*:Array<string>*/ = process.argv.slice(2);
  34. var filename/*:string*/ = "";
  35. var fmt/*:string*/ = "";
  36. var seed = 0, r = 10;
  37. for(var i = 0; i < args.length; ++i) {
  38. var arg = args[i];
  39. if(arg.charCodeAt(0) != 45) { if(filename === "") filename = arg; continue; }
  40. var m = arg.indexOf("=") == -1 ? arg : arg.substr(0, arg.indexOf("="));
  41. switch(m) {
  42. case "-": filename = "-"; break;
  43. case "--help": case "-h": process.exit(help()); break;
  44. case "--version": case "-V": process.exit(version()); break;
  45. case "--signed": case "-d": fmt = "%d"; break;
  46. case "--unsigned": case "-u": fmt = "%u"; break;
  47. case "--hex": case "-x": fmt = "%0.8x"; break;
  48. case "--HEX": case "-X": fmt = "%0.8X"; break;
  49. case "--format": case "-F":
  50. fmt = ((m!=arg) ? arg.substr(m.length+1) : args[++i])||""; break;
  51. case "--hex-seed": case "-H": r = 16;
  52. /* falls through */
  53. case "--seed": case "-S":
  54. seed=parseInt((m!=arg) ? arg.substr(m.length+1) : args[++i], r)||0; break;
  55. default: die("crc32: unrecognized option `" + arg + "'", 22);
  56. }
  57. }
  58. if(!process.stdin.isTTY) filename = filename || "-";
  59. if(filename.length===0) die("crc32: must specify a filename ('-' for stdin)",1);
  60. var crc32 = seed;
  61. // $FlowIgnore -- Writable is callable but type sig disagrees
  62. var writable = require('stream').Writable();
  63. writable._write = function(chunk, e, cb) { crc32 = X.buf(chunk, crc32); cb(); };
  64. writable._writev = function(chunks, cb) {
  65. chunks.forEach(function(c) { crc32 = X.buf(c.chunk, crc32);});
  66. cb();
  67. };
  68. writable.on('finish', function() {
  69. console.log(fmt === "" ? crc32 : require("printj").sprintf(fmt, crc32));
  70. });
  71. if(filename === "-") process.stdin.pipe(writable);
  72. else if(fs.existsSync(filename)) fs.createReadStream(filename).pipe(writable);
  73. else die("crc32: " + filename + ": No such file or directory", 2);