pem-jwk
Advanced tools
Comparing version 1.3.0 to 1.4.0
#!/usr/bin/env node | ||
var path = require('path') | ||
var fs = require('fs') | ||
var pj = require('../index') | ||
var filename = process.argv[2] | ||
if (!filename) { | ||
//TODO: use stdin | ||
console.error("Missing filename\nUsage:\n\tpem-jwk [filename]") | ||
process.exit(1) | ||
function convert(str) { | ||
if (str[0] === '{') { | ||
console.log(pj.jwk2pem(JSON.parse(str))) | ||
} | ||
else { | ||
console.log(pj.pem2jwk(str)) | ||
} | ||
} | ||
var filepath = path.resolve(process.cwd(), filename) | ||
try { | ||
var file = fs.readFileSync(filepath, 'utf8') | ||
} | ||
catch (e) { | ||
console.error('Could not read file: %s', filepath) | ||
process.exit(1) | ||
} | ||
if (file[0] === '{') { | ||
console.log(pj.jwk2pem(JSON.parse(file))) | ||
if (!filename) { | ||
var chunks = [] | ||
process.stdin.on('readable', function() { | ||
var chunk = process.stdin.read() | ||
if (chunk !== null) { | ||
chunks.push(chunk) | ||
} | ||
}) | ||
process.stdin.on('end', function () { | ||
convert(Buffer.concat(chunks).toString('utf8')) | ||
}) | ||
} | ||
else { | ||
console.log(pj.pem2jwk(file)) | ||
var path = require('path') | ||
var fs = require('fs') | ||
var filepath = path.resolve(process.cwd(), filename) | ||
try { | ||
convert(fs.readFileSync(filepath, 'utf8')) | ||
} | ||
catch (e) { | ||
console.error('Could not read file: %s', filepath) | ||
process.exit(1) | ||
} | ||
} | ||
{ | ||
"name": "pem-jwk", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "bin": "./bin/pem-jwk.js", |
12112
313