@smithy/hash-stream-node 2.0.18 → 2.1.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.
- package/dist-cjs/HashCalculator.js +1 -21
- package/dist-cjs/fileStreamHasher.js +1 -28
- package/dist-cjs/index.js +100 -5
- package/dist-cjs/readableStreamHasher.js +1 -23
- package/package.json +5 -5
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HashCalculator = void 0;
|
|
4
|
-
const util_utf8_1 = require("@smithy/util-utf8");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
class HashCalculator extends stream_1.Writable {
|
|
7
|
-
constructor(hash, options) {
|
|
8
|
-
super(options);
|
|
9
|
-
this.hash = hash;
|
|
10
|
-
}
|
|
11
|
-
_write(chunk, encoding, callback) {
|
|
12
|
-
try {
|
|
13
|
-
this.hash.update((0, util_utf8_1.toUint8Array)(chunk));
|
|
14
|
-
}
|
|
15
|
-
catch (err) {
|
|
16
|
-
return callback(err);
|
|
17
|
-
}
|
|
18
|
-
callback();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.HashCalculator = HashCalculator;
|
|
1
|
+
module.exports = require("./index.js");
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fileStreamHasher = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const HashCalculator_1 = require("./HashCalculator");
|
|
6
|
-
const fileStreamHasher = (hashCtor, fileStream) => new Promise((resolve, reject) => {
|
|
7
|
-
if (!isReadStream(fileStream)) {
|
|
8
|
-
reject(new Error("Unable to calculate hash for non-file streams."));
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const fileStreamTee = (0, fs_1.createReadStream)(fileStream.path, {
|
|
12
|
-
start: fileStream.start,
|
|
13
|
-
end: fileStream.end,
|
|
14
|
-
});
|
|
15
|
-
const hash = new hashCtor();
|
|
16
|
-
const hashCalculator = new HashCalculator_1.HashCalculator(hash);
|
|
17
|
-
fileStreamTee.pipe(hashCalculator);
|
|
18
|
-
fileStreamTee.on("error", (err) => {
|
|
19
|
-
hashCalculator.end();
|
|
20
|
-
reject(err);
|
|
21
|
-
});
|
|
22
|
-
hashCalculator.on("error", reject);
|
|
23
|
-
hashCalculator.on("finish", function () {
|
|
24
|
-
hash.digest().then(resolve).catch(reject);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
exports.fileStreamHasher = fileStreamHasher;
|
|
28
|
-
const isReadStream = (stream) => typeof stream.path === "string";
|
|
1
|
+
module.exports = require("./index.js");
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
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 src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
fileStreamHasher: () => fileStreamHasher,
|
|
24
|
+
readableStreamHasher: () => readableStreamHasher
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
|
|
28
|
+
// src/fileStreamHasher.ts
|
|
29
|
+
var import_fs = require("fs");
|
|
30
|
+
|
|
31
|
+
// src/HashCalculator.ts
|
|
32
|
+
var import_util_utf8 = require("@smithy/util-utf8");
|
|
33
|
+
var import_stream = require("stream");
|
|
34
|
+
var _HashCalculator = class _HashCalculator extends import_stream.Writable {
|
|
35
|
+
constructor(hash, options) {
|
|
36
|
+
super(options);
|
|
37
|
+
this.hash = hash;
|
|
38
|
+
}
|
|
39
|
+
_write(chunk, encoding, callback) {
|
|
40
|
+
try {
|
|
41
|
+
this.hash.update((0, import_util_utf8.toUint8Array)(chunk));
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return callback(err);
|
|
44
|
+
}
|
|
45
|
+
callback();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
__name(_HashCalculator, "HashCalculator");
|
|
49
|
+
var HashCalculator = _HashCalculator;
|
|
50
|
+
|
|
51
|
+
// src/fileStreamHasher.ts
|
|
52
|
+
var fileStreamHasher = /* @__PURE__ */ __name((hashCtor, fileStream) => new Promise((resolve, reject) => {
|
|
53
|
+
if (!isReadStream(fileStream)) {
|
|
54
|
+
reject(new Error("Unable to calculate hash for non-file streams."));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const fileStreamTee = (0, import_fs.createReadStream)(fileStream.path, {
|
|
58
|
+
start: fileStream.start,
|
|
59
|
+
end: fileStream.end
|
|
60
|
+
});
|
|
61
|
+
const hash = new hashCtor();
|
|
62
|
+
const hashCalculator = new HashCalculator(hash);
|
|
63
|
+
fileStreamTee.pipe(hashCalculator);
|
|
64
|
+
fileStreamTee.on("error", (err) => {
|
|
65
|
+
hashCalculator.end();
|
|
66
|
+
reject(err);
|
|
67
|
+
});
|
|
68
|
+
hashCalculator.on("error", reject);
|
|
69
|
+
hashCalculator.on("finish", function() {
|
|
70
|
+
hash.digest().then(resolve).catch(reject);
|
|
71
|
+
});
|
|
72
|
+
}), "fileStreamHasher");
|
|
73
|
+
var isReadStream = /* @__PURE__ */ __name((stream) => typeof stream.path === "string", "isReadStream");
|
|
74
|
+
|
|
75
|
+
// src/readableStreamHasher.ts
|
|
76
|
+
var readableStreamHasher = /* @__PURE__ */ __name((hashCtor, readableStream) => {
|
|
77
|
+
if (readableStream.readableFlowing !== null) {
|
|
78
|
+
throw new Error("Unable to calculate hash for flowing readable stream");
|
|
79
|
+
}
|
|
80
|
+
const hash = new hashCtor();
|
|
81
|
+
const hashCalculator = new HashCalculator(hash);
|
|
82
|
+
readableStream.pipe(hashCalculator);
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
readableStream.on("error", (err) => {
|
|
85
|
+
hashCalculator.end();
|
|
86
|
+
reject(err);
|
|
87
|
+
});
|
|
88
|
+
hashCalculator.on("error", reject);
|
|
89
|
+
hashCalculator.on("finish", () => {
|
|
90
|
+
hash.digest().then(resolve).catch(reject);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}, "readableStreamHasher");
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
fileStreamHasher,
|
|
98
|
+
readableStreamHasher
|
|
99
|
+
});
|
|
100
|
+
|
|
@@ -1,23 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readableStreamHasher = void 0;
|
|
4
|
-
const HashCalculator_1 = require("./HashCalculator");
|
|
5
|
-
const readableStreamHasher = (hashCtor, readableStream) => {
|
|
6
|
-
if (readableStream.readableFlowing !== null) {
|
|
7
|
-
throw new Error("Unable to calculate hash for flowing readable stream");
|
|
8
|
-
}
|
|
9
|
-
const hash = new hashCtor();
|
|
10
|
-
const hashCalculator = new HashCalculator_1.HashCalculator(hash);
|
|
11
|
-
readableStream.pipe(hashCalculator);
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
readableStream.on("error", (err) => {
|
|
14
|
-
hashCalculator.end();
|
|
15
|
-
reject(err);
|
|
16
|
-
});
|
|
17
|
-
hashCalculator.on("error", reject);
|
|
18
|
-
hashCalculator.on("finish", () => {
|
|
19
|
-
hash.digest().then(resolve).catch(reject);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
exports.readableStreamHasher = readableStreamHasher;
|
|
1
|
+
module.exports = require("./index.js");
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/hash-stream-node",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
|
-
"build:cjs": "
|
|
6
|
+
"build:cjs": "node ../../scripts/inline hash-stream-node",
|
|
7
7
|
"build:es": "yarn g:tsc -p tsconfig.es.json",
|
|
8
8
|
"build:types": "yarn g:tsc -p tsconfig.types.json",
|
|
9
9
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@smithy/types": "^2.
|
|
26
|
-
"@smithy/util-utf8": "^2.
|
|
25
|
+
"@smithy/types": "^2.9.1",
|
|
26
|
+
"@smithy/util-utf8": "^2.1.1",
|
|
27
27
|
"tslib": "^2.5.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@aws-crypto/sha256-js": "3.0.0",
|
|
31
|
-
"@smithy/util-hex-encoding": "^2.
|
|
31
|
+
"@smithy/util-hex-encoding": "^2.1.1",
|
|
32
32
|
"@tsconfig/recommended": "1.0.1",
|
|
33
33
|
"@types/node": "^14.14.31",
|
|
34
34
|
"concurrently": "7.0.0",
|