@smithy/hash-stream-node
Advanced tools
Comparing version 2.0.18 to 2.1.0
@@ -1,28 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fileStreamHasher = void 0; | ||
const fs_1 = require("fs"); | ||
const HashCalculator_1 = require("./HashCalculator"); | ||
const fileStreamHasher = (hashCtor, fileStream) => new Promise((resolve, reject) => { | ||
if (!isReadStream(fileStream)) { | ||
reject(new Error("Unable to calculate hash for non-file streams.")); | ||
return; | ||
} | ||
const fileStreamTee = (0, fs_1.createReadStream)(fileStream.path, { | ||
start: fileStream.start, | ||
end: fileStream.end, | ||
}); | ||
const hash = new hashCtor(); | ||
const hashCalculator = new HashCalculator_1.HashCalculator(hash); | ||
fileStreamTee.pipe(hashCalculator); | ||
fileStreamTee.on("error", (err) => { | ||
hashCalculator.end(); | ||
reject(err); | ||
}); | ||
hashCalculator.on("error", reject); | ||
hashCalculator.on("finish", function () { | ||
hash.digest().then(resolve).catch(reject); | ||
}); | ||
}); | ||
exports.fileStreamHasher = fileStreamHasher; | ||
const isReadStream = (stream) => typeof stream.path === "string"; | ||
module.exports = require("./index.js"); |
@@ -1,21 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HashCalculator = void 0; | ||
const util_utf8_1 = require("@smithy/util-utf8"); | ||
const stream_1 = require("stream"); | ||
class HashCalculator extends stream_1.Writable { | ||
constructor(hash, options) { | ||
super(options); | ||
this.hash = hash; | ||
} | ||
_write(chunk, encoding, callback) { | ||
try { | ||
this.hash.update((0, util_utf8_1.toUint8Array)(chunk)); | ||
} | ||
catch (err) { | ||
return callback(err); | ||
} | ||
callback(); | ||
} | ||
} | ||
exports.HashCalculator = HashCalculator; | ||
module.exports = require("./index.js"); |
@@ -1,5 +0,98 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./fileStreamHasher"), exports); | ||
tslib_1.__exportStar(require("./readableStreamHasher"), exports); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
fileStreamHasher: () => fileStreamHasher, | ||
readableStreamHasher: () => readableStreamHasher | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/fileStreamHasher.ts | ||
var import_fs = require("fs"); | ||
// src/HashCalculator.ts | ||
var import_util_utf8 = require("@smithy/util-utf8"); | ||
var import_stream = require("stream"); | ||
var _HashCalculator = class _HashCalculator extends import_stream.Writable { | ||
constructor(hash, options) { | ||
super(options); | ||
this.hash = hash; | ||
} | ||
_write(chunk, encoding, callback) { | ||
try { | ||
this.hash.update((0, import_util_utf8.toUint8Array)(chunk)); | ||
} catch (err) { | ||
return callback(err); | ||
} | ||
callback(); | ||
} | ||
}; | ||
__name(_HashCalculator, "HashCalculator"); | ||
var HashCalculator = _HashCalculator; | ||
// src/fileStreamHasher.ts | ||
var fileStreamHasher = /* @__PURE__ */ __name((hashCtor, fileStream) => new Promise((resolve, reject) => { | ||
if (!isReadStream(fileStream)) { | ||
reject(new Error("Unable to calculate hash for non-file streams.")); | ||
return; | ||
} | ||
const fileStreamTee = (0, import_fs.createReadStream)(fileStream.path, { | ||
start: fileStream.start, | ||
end: fileStream.end | ||
}); | ||
const hash = new hashCtor(); | ||
const hashCalculator = new HashCalculator(hash); | ||
fileStreamTee.pipe(hashCalculator); | ||
fileStreamTee.on("error", (err) => { | ||
hashCalculator.end(); | ||
reject(err); | ||
}); | ||
hashCalculator.on("error", reject); | ||
hashCalculator.on("finish", function() { | ||
hash.digest().then(resolve).catch(reject); | ||
}); | ||
}), "fileStreamHasher"); | ||
var isReadStream = /* @__PURE__ */ __name((stream) => typeof stream.path === "string", "isReadStream"); | ||
// src/readableStreamHasher.ts | ||
var readableStreamHasher = /* @__PURE__ */ __name((hashCtor, readableStream) => { | ||
if (readableStream.readableFlowing !== null) { | ||
throw new Error("Unable to calculate hash for flowing readable stream"); | ||
} | ||
const hash = new hashCtor(); | ||
const hashCalculator = new HashCalculator(hash); | ||
readableStream.pipe(hashCalculator); | ||
return new Promise((resolve, reject) => { | ||
readableStream.on("error", (err) => { | ||
hashCalculator.end(); | ||
reject(err); | ||
}); | ||
hashCalculator.on("error", reject); | ||
hashCalculator.on("finish", () => { | ||
hash.digest().then(resolve).catch(reject); | ||
}); | ||
}); | ||
}, "readableStreamHasher"); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
fileStreamHasher, | ||
readableStreamHasher | ||
}); |
@@ -1,23 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.readableStreamHasher = void 0; | ||
const HashCalculator_1 = require("./HashCalculator"); | ||
const readableStreamHasher = (hashCtor, readableStream) => { | ||
if (readableStream.readableFlowing !== null) { | ||
throw new Error("Unable to calculate hash for flowing readable stream"); | ||
} | ||
const hash = new hashCtor(); | ||
const hashCalculator = new HashCalculator_1.HashCalculator(hash); | ||
readableStream.pipe(hashCalculator); | ||
return new Promise((resolve, reject) => { | ||
readableStream.on("error", (err) => { | ||
hashCalculator.end(); | ||
reject(err); | ||
}); | ||
hashCalculator.on("error", reject); | ||
hashCalculator.on("finish", () => { | ||
hash.digest().then(resolve).catch(reject); | ||
}); | ||
}); | ||
}; | ||
exports.readableStreamHasher = readableStreamHasher; | ||
module.exports = require("./index.js"); |
{ | ||
"name": "@smithy/hash-stream-node", | ||
"version": "2.0.18", | ||
"version": "2.1.0", | ||
"scripts": { | ||
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'", | ||
"build:cjs": "yarn g:tsc -p tsconfig.cjs.json", | ||
"build:cjs": "node ../../scripts/inline hash-stream-node", | ||
"build:es": "yarn g:tsc -p tsconfig.es.json", | ||
@@ -25,4 +25,4 @@ "build:types": "yarn g:tsc -p tsconfig.types.json", | ||
"dependencies": { | ||
"@smithy/types": "^2.8.0", | ||
"@smithy/util-utf8": "^2.0.2", | ||
"@smithy/types": "^2.9.0", | ||
"@smithy/util-utf8": "^2.1.0", | ||
"tslib": "^2.5.0" | ||
@@ -32,3 +32,3 @@ }, | ||
"@aws-crypto/sha256-js": "3.0.0", | ||
"@smithy/util-hex-encoding": "^2.0.0", | ||
"@smithy/util-hex-encoding": "^2.1.0", | ||
"@tsconfig/recommended": "1.0.1", | ||
@@ -35,0 +35,0 @@ "@types/node": "^14.14.31", |
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
21317
222
Updated@smithy/types@^2.9.0
Updated@smithy/util-utf8@^2.1.0