@cumulus/checksum
Advanced tools
Comparing version 10.0.0-beta.0 to 10.0.0
/// <reference types="node" /> | ||
import { Readable, TransformOptions } from 'stream'; | ||
export declare function normalizeHashAlgorithm(algorithm: string): string; | ||
/** | ||
@@ -4,0 +5,0 @@ * Create <algorithm> file checksum from readable stream |
@@ -22,5 +22,22 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateChecksumFromStream = void 0; | ||
exports.generateChecksumFromStream = exports.normalizeHashAlgorithm = void 0; | ||
const cksum = __importStar(require("cksum")); | ||
const crypto = __importStar(require("crypto")); | ||
function normalizeHashAlgorithm(algorithm) { | ||
switch (algorithm) { | ||
case 'SHA-1': | ||
return 'SHA1'; | ||
case 'SHA-2': | ||
return 'SHA2'; | ||
case 'SHA-256': | ||
return 'SHA256'; | ||
case 'SHA-384': | ||
return 'SHA384'; | ||
case 'SHA-512': | ||
return 'SHA512'; | ||
default: | ||
return algorithm; | ||
} | ||
} | ||
exports.normalizeHashAlgorithm = normalizeHashAlgorithm; | ||
// Calculate the cksum of a readable stream | ||
@@ -34,4 +51,5 @@ async function getCksumFromStream(stream) { | ||
async function getChecksumFromStream(algorithm, stream, options = {}) { | ||
const normalizedAlgorithm = normalizeHashAlgorithm(algorithm); | ||
return await new Promise((resolve, reject) => { | ||
const hash = crypto.createHash(algorithm, options); | ||
const hash = crypto.createHash(normalizedAlgorithm, options); | ||
stream.on('error', reject); | ||
@@ -38,0 +56,0 @@ stream.on('data', (chunk) => hash.update(chunk)); |
{ | ||
"name": "@cumulus/checksum", | ||
"version": "10.0.0-beta.0", | ||
"version": "10.0.0", | ||
"description": "Cumulus checksum utilities", | ||
@@ -42,3 +42,3 @@ "engines": { | ||
}, | ||
"gitHead": "bc283986be627ba06a4084cabd4e01d1540d14c7" | ||
"gitHead": "7c6d2d1cd79b57d6943bbc3d898d0cf975b543b1" | ||
} |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19733
141
0