@cumulus/checksum 10.0.0-beta.0 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checksum.d.ts +1 -0
- package/dist/checksum.js +25 -3
- package/package.json +2 -2
package/dist/checksum.d.ts
CHANGED
package/dist/checksum.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -19,9 +23,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.generateChecksumFromStream = void 0;
|
|
26
|
+
exports.generateChecksumFromStream = exports.normalizeHashAlgorithm = void 0;
|
|
23
27
|
const cksum = __importStar(require("cksum"));
|
|
24
28
|
const crypto = __importStar(require("crypto"));
|
|
29
|
+
function normalizeHashAlgorithm(algorithm) {
|
|
30
|
+
switch (algorithm) {
|
|
31
|
+
case 'SHA-1':
|
|
32
|
+
return 'SHA1';
|
|
33
|
+
case 'SHA-2':
|
|
34
|
+
return 'SHA2';
|
|
35
|
+
case 'SHA-256':
|
|
36
|
+
return 'SHA256';
|
|
37
|
+
case 'SHA-384':
|
|
38
|
+
return 'SHA384';
|
|
39
|
+
case 'SHA-512':
|
|
40
|
+
return 'SHA512';
|
|
41
|
+
default:
|
|
42
|
+
return algorithm;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.normalizeHashAlgorithm = normalizeHashAlgorithm;
|
|
25
46
|
// Calculate the cksum of a readable stream
|
|
26
47
|
async function getCksumFromStream(stream) {
|
|
27
48
|
return await new Promise((resolve, reject) => stream
|
|
@@ -30,8 +51,9 @@ async function getCksumFromStream(stream) {
|
|
|
30
51
|
}
|
|
31
52
|
// Calculate the hash of a readable stream using `crypto.createHash()`
|
|
32
53
|
async function getChecksumFromStream(algorithm, stream, options = {}) {
|
|
54
|
+
const normalizedAlgorithm = normalizeHashAlgorithm(algorithm);
|
|
33
55
|
return await new Promise((resolve, reject) => {
|
|
34
|
-
const hash = crypto.createHash(
|
|
56
|
+
const hash = crypto.createHash(normalizedAlgorithm, options);
|
|
35
57
|
stream.on('error', reject);
|
|
36
58
|
stream.on('data', (chunk) => hash.update(chunk));
|
|
37
59
|
stream.on('end', () => resolve(hash.digest('hex')));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/checksum",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
4
4
|
"description": "Cumulus checksum utilities",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12.18.0"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"cksum": "^1.3.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e678a624b5179759200b988de72292ce389f41e2"
|
|
43
43
|
}
|