@smithy/hash-stream-node 4.1.0 → 4.2.0
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-cjs/index.js
CHANGED
|
@@ -1,101 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
fileStreamHasher: () => fileStreamHasher,
|
|
24
|
-
readableStreamHasher: () => readableStreamHasher
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
'use strict';
|
|
27
2
|
|
|
28
|
-
|
|
29
|
-
var
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var utilUtf8 = require('@smithy/util-utf8');
|
|
5
|
+
var stream = require('stream');
|
|
30
6
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
super(options);
|
|
37
|
-
this.hash = hash;
|
|
38
|
-
}
|
|
39
|
-
static {
|
|
40
|
-
__name(this, "HashCalculator");
|
|
41
|
-
}
|
|
42
|
-
_write(chunk, encoding, callback) {
|
|
43
|
-
try {
|
|
44
|
-
this.hash.update((0, import_util_utf8.toUint8Array)(chunk));
|
|
45
|
-
} catch (err) {
|
|
46
|
-
return callback(err);
|
|
7
|
+
class HashCalculator extends stream.Writable {
|
|
8
|
+
hash;
|
|
9
|
+
constructor(hash, options) {
|
|
10
|
+
super(options);
|
|
11
|
+
this.hash = hash;
|
|
47
12
|
}
|
|
48
|
-
callback
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const fileStreamTee = (0, import_fs.createReadStream)(fileStream.path, {
|
|
59
|
-
start: fileStream.start,
|
|
60
|
-
end: fileStream.end
|
|
61
|
-
});
|
|
62
|
-
const hash = new hashCtor();
|
|
63
|
-
const hashCalculator = new HashCalculator(hash);
|
|
64
|
-
fileStreamTee.pipe(hashCalculator);
|
|
65
|
-
fileStreamTee.on("error", (err) => {
|
|
66
|
-
hashCalculator.end();
|
|
67
|
-
reject(err);
|
|
68
|
-
});
|
|
69
|
-
hashCalculator.on("error", reject);
|
|
70
|
-
hashCalculator.on("finish", function() {
|
|
71
|
-
hash.digest().then(resolve).catch(reject);
|
|
72
|
-
});
|
|
73
|
-
}), "fileStreamHasher");
|
|
74
|
-
var isReadStream = /* @__PURE__ */ __name((stream) => typeof stream.path === "string", "isReadStream");
|
|
13
|
+
_write(chunk, encoding, callback) {
|
|
14
|
+
try {
|
|
15
|
+
this.hash.update(utilUtf8.toUint8Array(chunk));
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
return callback(err);
|
|
19
|
+
}
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
75
23
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
24
|
+
const fileStreamHasher = (hashCtor, fileStream) => new Promise((resolve, reject) => {
|
|
25
|
+
if (!isReadStream(fileStream)) {
|
|
26
|
+
reject(new Error("Unable to calculate hash for non-file streams."));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const fileStreamTee = fs.createReadStream(fileStream.path, {
|
|
30
|
+
start: fileStream.start,
|
|
31
|
+
end: fileStream.end,
|
|
32
|
+
});
|
|
33
|
+
const hash = new hashCtor();
|
|
34
|
+
const hashCalculator = new HashCalculator(hash);
|
|
35
|
+
fileStreamTee.pipe(hashCalculator);
|
|
36
|
+
fileStreamTee.on("error", (err) => {
|
|
37
|
+
hashCalculator.end();
|
|
38
|
+
reject(err);
|
|
88
39
|
});
|
|
89
40
|
hashCalculator.on("error", reject);
|
|
90
|
-
hashCalculator.on("finish", ()
|
|
91
|
-
|
|
41
|
+
hashCalculator.on("finish", function () {
|
|
42
|
+
hash.digest().then(resolve).catch(reject);
|
|
92
43
|
});
|
|
93
|
-
});
|
|
94
|
-
}, "readableStreamHasher");
|
|
95
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
-
|
|
97
|
-
0 && (module.exports = {
|
|
98
|
-
fileStreamHasher,
|
|
99
|
-
readableStreamHasher
|
|
100
44
|
});
|
|
45
|
+
const isReadStream = (stream) => typeof stream.path === "string";
|
|
46
|
+
|
|
47
|
+
const readableStreamHasher = (hashCtor, readableStream) => {
|
|
48
|
+
if (readableStream.readableFlowing !== null) {
|
|
49
|
+
throw new Error("Unable to calculate hash for flowing readable stream");
|
|
50
|
+
}
|
|
51
|
+
const hash = new hashCtor();
|
|
52
|
+
const hashCalculator = new HashCalculator(hash);
|
|
53
|
+
readableStream.pipe(hashCalculator);
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
readableStream.on("error", (err) => {
|
|
56
|
+
hashCalculator.end();
|
|
57
|
+
reject(err);
|
|
58
|
+
});
|
|
59
|
+
hashCalculator.on("error", reject);
|
|
60
|
+
hashCalculator.on("finish", () => {
|
|
61
|
+
hash.digest().then(resolve).catch(reject);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
101
65
|
|
|
66
|
+
exports.fileStreamHasher = fileStreamHasher;
|
|
67
|
+
exports.readableStreamHasher = readableStreamHasher;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/hash-stream-node",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "node ../../scripts/inline hash-stream-node",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@smithy/types": "^4.
|
|
28
|
-
"@smithy/util-utf8": "^4.
|
|
27
|
+
"@smithy/types": "^4.6.0",
|
|
28
|
+
"@smithy/util-utf8": "^4.2.0",
|
|
29
29
|
"tslib": "^2.6.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
33
|
-
"@smithy/util-hex-encoding": "^4.
|
|
33
|
+
"@smithy/util-hex-encoding": "^4.2.0",
|
|
34
34
|
"@types/node": "^18.11.9",
|
|
35
35
|
"concurrently": "7.0.0",
|
|
36
36
|
"downlevel-dts": "0.10.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("./index.js");
|