2019-09-25 21:50:07 +00:00
|
|
|
const { spawnSync } = require('child_process');
|
|
|
|
|
2019-06-26 01:15:00 +00:00
|
|
|
function fromCodePoint(codepoint) {
|
|
|
|
var code = typeof codepoint === 'string' ?
|
|
|
|
parseInt(codepoint, 16) : codepoint;
|
|
|
|
if (code < 0x10000) {
|
|
|
|
return String.fromCharCode(code);
|
|
|
|
}
|
|
|
|
code -= 0x10000;
|
|
|
|
return String.fromCharCode(
|
|
|
|
0xD800 + (code >> 10),
|
|
|
|
0xDC00 + (code & 0x3FF)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
module.exports.fromCodePoint = fromCodePoint;
|
|
|
|
|
|
|
|
function toJSON(codePoints) {
|
|
|
|
return codePoints.split('-').map(function (point) {
|
|
|
|
return UTF162JSON(fromCodePoint(point));
|
|
|
|
}).join('');
|
|
|
|
}
|
|
|
|
module.exports.toJSON = toJSON;
|
|
|
|
|
|
|
|
function UTF162JSON(text) {
|
|
|
|
for (var i = 0, r = []; i < text.length; i++) {
|
|
|
|
r.push('\\u' + ('000' + text.charCodeAt(i).toString(16)).slice(-4));
|
|
|
|
}
|
|
|
|
return r.join('');
|
|
|
|
}
|
|
|
|
module.exports.UTF162JSON = UTF162JSON;
|
2019-09-25 21:50:07 +00:00
|
|
|
|
|
|
|
function getIntegrityHash(filename) {
|
|
|
|
const algorithm = 'sha384';
|
|
|
|
const digest = spawnSync('openssl', ['dgst', `-${algorithm}`, '-binary', filename]);
|
|
|
|
if (digest.status || digest.signal){
|
|
|
|
throw new Error(digest.stderr.toString('utf8'));
|
|
|
|
}
|
|
|
|
return `${algorithm}-${digest.stdout.toString('base64')}`;
|
|
|
|
}
|
|
|
|
module.exports.getIntegrityHash = getIntegrityHash;
|