Comparing version 1.0.0 to 1.0.1
127
index.js
@@ -1,2 +0,1 @@ | ||
#!/usr/bin/env node | ||
/* index.js (C) 2020-present SheetJS -- http://sheetjs.com */ | ||
@@ -11,21 +10,22 @@ /* eslint-env node */ | ||
function help()/*:number*/ { | ||
[ | ||
"usage: crc32 [options] [filename]", | ||
"", | ||
"Options:", | ||
" -h, --help output usage information", | ||
" -V, --version output the version number", | ||
" -S, --seed=<n> use integer seed as starting value (rolling CRC)", | ||
" -H, --hex-seed=<h> use hex seed as starting value (rolling CRC)", | ||
" -d, --signed print result with format `%d` (default)", | ||
" -u, --unsigned print result with format `%u`", | ||
" -x, --hex print result with format `%0.8x`", | ||
" -X, --HEX print result with format `%0.8X`", | ||
" -F, --format=<s> use specified printf format", | ||
"", | ||
"Set filename = '-' or pipe data into crc32 to read from stdin", | ||
"Default output mode is signed (-d)", | ||
"" | ||
].forEach(function (l) { console.log(l); }); | ||
return 0; | ||
[ | ||
"usage: crc32 [options] [filename]", | ||
"", | ||
"Options:", | ||
" -h, --help output usage information", | ||
" -V, --version output the version number", | ||
" -S, --seed=<n> use integer seed as starting value (rolling CRC)", | ||
" -H, --hex-seed=<h> use hex seed as starting value (rolling CRC)", | ||
" -d, --signed print result with format `%d` (default)", | ||
" -u, --unsigned print result with format `%u`", | ||
" -x, --hex print result with format `%0.8x`", | ||
" -X, --HEX print result with format `%0.8X`", | ||
" -c, --crc32c use CRC32C (Castagnoli)", | ||
" -F, --format=<s> use specified printf format", | ||
"", | ||
"Set filename = '-' or pipe data into crc32 to read from stdin", | ||
"Default output mode is signed (-d)", | ||
"" | ||
].forEach(function (l) { console.log(l); }); | ||
return 0; | ||
} | ||
@@ -41,53 +41,56 @@ | ||
function run() { | ||
var args/*:Array<string>*/ = process.argv.slice(2); | ||
var filename/*:string*/ = ""; | ||
var fmt/*:string*/ = ""; | ||
var seed = 0, r = 10; | ||
var args/*:Array<string>*/ = process.argv.slice(2); | ||
var filename/*:string*/ = ""; | ||
var fmt/*:string*/ = ""; | ||
var seed = 0, r = 10; | ||
for (var i = 0; i < args.length; ++i) { | ||
var arg = args[i]; | ||
if (arg.charCodeAt(0) != 45) { if (filename === "") filename = arg; continue; } | ||
var m = arg.indexOf("=") == -1 ? arg : arg.substr(0, arg.indexOf("=")); | ||
switch (m) { | ||
case "-": filename = "-"; break; | ||
for(var i = 0; i < args.length; ++i) { | ||
var arg = args[i]; | ||
if(arg.charCodeAt(0) != 45) { if(filename === "") filename = arg; continue; } | ||
var m = arg.indexOf("=") == -1 ? arg : arg.substr(0, arg.indexOf("=")); | ||
switch(m) { | ||
case "-": filename = "-"; break; | ||
case "--help": case "-h": process.exit(help()); break; | ||
case "--version": case "-V": process.exit(version()); break; | ||
case "--help": case "-h": process.exit(help()); break; | ||
case "--version": case "-V": process.exit(version()); break; | ||
case "--signed": case "-d": fmt = "%d"; break; | ||
case "--unsigned": case "-u": fmt = "%u"; break; | ||
case "--hex": case "-x": fmt = "%0.8x"; break; | ||
case "--HEX": case "-X": fmt = "%0.8X"; break; | ||
case "--format": case "-F": | ||
fmt = ((m != arg) ? arg.substr(m.length + 1) : args[++i]) || ""; break; | ||
case "--crc32c": case "-c": try { X = require('../crc32c'); } catch(e) { X = require('crc-32/crc32c'); } break; | ||
case "--hex-seed": case "-H": r = 16; | ||
/* falls through */ | ||
case "--seed": case "-S": | ||
seed = parseInt((m != arg) ? arg.substr(m.length + 1) : args[++i], r) || 0; break; | ||
case "--signed": case "-d": fmt = "%d"; break; | ||
case "--unsigned": case "-u": fmt = "%u"; break; | ||
case "--hex": case "-x": fmt = "%0.8x"; break; | ||
case "--HEX": case "-X": fmt = "%0.8X"; break; | ||
case "--format": case "-F": | ||
fmt = ((m!=arg) ? arg.substr(m.length+1) : args[++i])||""; break; | ||
default: die("crc32: unrecognized option `" + arg + "'", 22); | ||
} | ||
} | ||
case "--hex-seed": case "-H": r = 16; | ||
/* falls through */ | ||
case "--seed": case "-S": | ||
seed=parseInt((m!=arg) ? arg.substr(m.length+1) : args[++i], r)||0; break; | ||
if (!process.stdin.isTTY) filename = filename || "-"; | ||
if (filename.length === 0) die("crc32: must specify a filename ('-' for stdin)", 1); | ||
default: die("crc32: unrecognized option `" + arg + "'", 22); | ||
} | ||
} | ||
var crc32 = seed; | ||
// $FlowIgnore -- Writable is callable but type sig disagrees | ||
var writable = require('stream').Writable(); | ||
writable._write = function (chunk, e, cb) { crc32 = X.buf(chunk, crc32); cb(); }; | ||
writable._writev = function (chunks, cb) { | ||
chunks.forEach(function (c) { crc32 = X.buf(c.chunk, crc32); }); | ||
cb(); | ||
}; | ||
writable.on('finish', function () { | ||
console.log(fmt === "" ? crc32 : require("printj").sprintf(fmt, crc32)); | ||
}); | ||
if(!process.stdin.isTTY) filename = filename || "-"; | ||
if(filename.length===0) die("crc32: must specify a filename ('-' for stdin)",1); | ||
if (filename === "-") process.stdin.pipe(writable); | ||
else if (fs.existsSync(filename)) fs.createReadStream(filename).pipe(writable); | ||
else die("crc32: " + filename + ": No such file or directory", 2); | ||
var crc32 = seed; | ||
// $FlowIgnore -- Writable is callable but type sig disagrees | ||
var writable = require('stream').Writable(); | ||
writable._write = function(chunk, e, cb) { crc32 = X.buf(chunk, crc32); cb(); }; | ||
writable._writev = function(chunks, cb) { | ||
chunks.forEach(function(c) { crc32 = X.buf(c.chunk, crc32);}); | ||
cb(); | ||
}; | ||
writable.on('finish', function() { | ||
console.log(fmt === "" ? crc32 : require("printj").sprintf(fmt, crc32)); | ||
}); | ||
if(filename === "-") process.stdin.pipe(writable); | ||
else if(fs.existsSync(filename)) fs.createReadStream(filename).pipe(writable); | ||
else die("crc32: " + filename + ": No such file or directory", 2); | ||
} | ||
module.exports = run; | ||
module.exports = run; | ||
{ | ||
"name": "crc32-cli", | ||
"version": "1.0.0", | ||
"description": "Command-line interface for crc32", | ||
"bin": { | ||
"crc32-cli": "./bin/crc32.njs" | ||
}, | ||
"main": "index.js", | ||
"author": "Garrett Luu", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"crc-32": "^1.2.0", | ||
"exit-on-epipe": "^1.0.1", | ||
"fs": "0.0.1-security" | ||
} | ||
"name": "crc32-cli", | ||
"version": "1.0.1", | ||
"author": "sheetjs", | ||
"description": "Command-line interface for crc32", | ||
"bin": { | ||
"crc32-cli": "bin/crc32.njs" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"crc-32": "^1.2.1", | ||
"exit-on-epipe": "~1.0.1" | ||
}, | ||
"license": "Apache-2.0" | ||
} | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
77
3810
3
1
- Removedfs@0.0.1-security
- Removedfs@0.0.1-security(transitive)
Updatedcrc-32@^1.2.1
Updatedexit-on-epipe@~1.0.1