@cumulus/checksum 9.8.0 → 10.0.1

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.
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable, TransformOptions } from 'stream';
3
+ export declare function normalizeHashAlgorithm(algorithm: string): string;
3
4
  /**
4
5
  * Create <algorithm> file checksum from readable stream
5
6
  *
package/dist/checksum.js CHANGED
@@ -19,19 +19,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.generateChecksumFromStream = void 0;
22
+ exports.generateChecksumFromStream = exports.normalizeHashAlgorithm = void 0;
23
23
  const cksum = __importStar(require("cksum"));
24
24
  const crypto = __importStar(require("crypto"));
25
+ function normalizeHashAlgorithm(algorithm) {
26
+ switch (algorithm) {
27
+ case 'SHA-1':
28
+ return 'SHA1';
29
+ case 'SHA-2':
30
+ return 'SHA2';
31
+ case 'SHA-256':
32
+ return 'SHA256';
33
+ case 'SHA-384':
34
+ return 'SHA384';
35
+ case 'SHA-512':
36
+ return 'SHA512';
37
+ default:
38
+ return algorithm;
39
+ }
40
+ }
41
+ exports.normalizeHashAlgorithm = normalizeHashAlgorithm;
25
42
  // Calculate the cksum of a readable stream
26
43
  async function getCksumFromStream(stream) {
27
44
  return await new Promise((resolve, reject) => stream
28
- .pipe(cksum.stream((value) => resolve(value.readUInt32BE(0))))
45
+ .pipe(cksum.stream((value) => resolve(value.readUInt32BE(0).toString())))
29
46
  .on('error', reject));
30
47
  }
31
48
  // Calculate the hash of a readable stream using `crypto.createHash()`
32
49
  async function getChecksumFromStream(algorithm, stream, options = {}) {
50
+ const normalizedAlgorithm = normalizeHashAlgorithm(algorithm);
33
51
  return await new Promise((resolve, reject) => {
34
- const hash = crypto.createHash(algorithm, options);
52
+ const hash = crypto.createHash(normalizedAlgorithm, options);
35
53
  stream.on('error', reject);
36
54
  stream.on('data', (chunk) => hash.update(chunk));
37
55
  stream.on('end', () => resolve(hash.digest('hex')));
package/dist/validate.js CHANGED
@@ -16,7 +16,7 @@ const checksum_1 = require("./checksum");
16
16
  */
17
17
  async function validateChecksumFromStream(algorithm, stream, expectedSum, options = {}) {
18
18
  const calculatedSum = await (0, checksum_1.generateChecksumFromStream)(algorithm, stream, options);
19
- return expectedSum === calculatedSum;
19
+ return expectedSum.toString() === calculatedSum.toString();
20
20
  }
21
21
  exports.validateChecksumFromStream = validateChecksumFromStream;
22
22
  //# sourceMappingURL=validate.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/checksum",
3
- "version": "9.8.0",
3
+ "version": "10.0.1",
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": "913034ba6814e562b7f3d58bb39cf086255a6efd"
42
+ "gitHead": "49c3c88336838184f22f35fbce298c71cd269138"
43
43
  }