@smithy/hash-stream-node 4.2.13 → 4.3.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 +6 -67
- package/dist-es/index.js +1 -2
- package/dist-types/index.d.ts +2 -8
- package/package.json +5 -29
- package/README.md +0 -17
- package/dist-es/HashCalculator.js +0 -18
- package/dist-es/fileStreamHasher.js +0 -24
- package/dist-es/readableStreamHasher.js +0 -19
- package/dist-types/HashCalculator.d.ts +0 -11
- package/dist-types/fileStreamHasher.d.ts +0 -6
- package/dist-types/readableStreamHasher.d.ts +0 -6
package/dist-cjs/index.js
CHANGED
|
@@ -1,67 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class HashCalculator extends stream.Writable {
|
|
8
|
-
hash;
|
|
9
|
-
constructor(hash, options) {
|
|
10
|
-
super(options);
|
|
11
|
-
this.hash = hash;
|
|
12
|
-
}
|
|
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
|
-
}
|
|
23
|
-
|
|
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);
|
|
39
|
-
});
|
|
40
|
-
hashCalculator.on("error", reject);
|
|
41
|
-
hashCalculator.on("finish", function () {
|
|
42
|
-
hash.digest().then(resolve).catch(reject);
|
|
43
|
-
});
|
|
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
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.fileStreamHasher = fileStreamHasher;
|
|
67
|
-
exports.readableStreamHasher = readableStreamHasher;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readableStreamHasher = exports.fileStreamHasher = void 0;
|
|
4
|
+
var checksum_1 = require("@smithy/core/checksum");
|
|
5
|
+
Object.defineProperty(exports, "fileStreamHasher", { enumerable: true, get: function () { return checksum_1.fileStreamHasher; } });
|
|
6
|
+
Object.defineProperty(exports, "readableStreamHasher", { enumerable: true, get: function () { return checksum_1.readableStreamHasher; } });
|
package/dist-es/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./readableStreamHasher";
|
|
1
|
+
export { fileStreamHasher, readableStreamHasher } from "@smithy/core/checksum";
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
export * from "./fileStreamHasher";
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export * from "./readableStreamHasher";
|
|
1
|
+
/** @deprecated Use @smithy/core/serde instead. */
|
|
2
|
+
export { fileStreamHasher, readableStreamHasher } from "@smithy/core/checksum";
|
package/package.json
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/hash-stream-node",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
|
|
9
|
-
"clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
|
|
10
|
-
"format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
|
|
11
|
-
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
|
|
12
|
-
"stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
|
|
13
|
-
"test": "yarn g:vitest run",
|
|
14
|
-
"test:watch": "yarn g:vitest watch"
|
|
5
|
+
"build": "yarn g:tsc -p tsconfig.cjs.json && yarn g:tsc -p tsconfig.es.json && yarn g:tsc -p tsconfig.types.json",
|
|
6
|
+
"clean": "rm -rf dist-cjs dist-es dist-types",
|
|
7
|
+
"stage-release": "rm -rf .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz"
|
|
15
8
|
},
|
|
16
9
|
"main": "./dist-cjs/index.js",
|
|
17
10
|
"module": "./dist-es/index.js",
|
|
@@ -23,29 +16,12 @@
|
|
|
23
16
|
"license": "Apache-2.0",
|
|
24
17
|
"sideEffects": false,
|
|
25
18
|
"dependencies": {
|
|
26
|
-
"@smithy/
|
|
27
|
-
"@smithy/util-utf8": "^4.2.2",
|
|
19
|
+
"@smithy/core": "^3.24.0",
|
|
28
20
|
"tslib": "^2.6.2"
|
|
29
21
|
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@aws-crypto/sha256-js": "5.2.0",
|
|
32
|
-
"@smithy/util-hex-encoding": "^4.2.2",
|
|
33
|
-
"@types/node": "^18.11.9",
|
|
34
|
-
"concurrently": "7.0.0",
|
|
35
|
-
"downlevel-dts": "0.10.1",
|
|
36
|
-
"premove": "4.0.0",
|
|
37
|
-
"typedoc": "0.23.23"
|
|
38
|
-
},
|
|
39
22
|
"engines": {
|
|
40
23
|
"node": ">=18.0.0"
|
|
41
24
|
},
|
|
42
|
-
"typesVersions": {
|
|
43
|
-
"<4.5": {
|
|
44
|
-
"dist-types/*": [
|
|
45
|
-
"dist-types/ts3.4/*"
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
25
|
"files": [
|
|
50
26
|
"dist-*/**"
|
|
51
27
|
],
|
package/README.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# @smithy/hash-stream-node
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@smithy/hash-stream-node)
|
|
4
|
-
[](https://www.npmjs.com/package/@smithy/hash-stream-node)
|
|
5
|
-
|
|
6
|
-
### :warning: Internal API :warning:
|
|
7
|
-
|
|
8
|
-
> This is an internal package.
|
|
9
|
-
> That means this is used as a dependency for other, public packages, but
|
|
10
|
-
> should not be taken directly as a dependency in your application's `package.json`.
|
|
11
|
-
|
|
12
|
-
> If you are updating the version of this package, for example to bring in a
|
|
13
|
-
> bug-fix, you should do so by updating your application lockfile with
|
|
14
|
-
> e.g. `npm up @scope/package` or equivalent command in another
|
|
15
|
-
> package manager, rather than taking a direct dependency.
|
|
16
|
-
|
|
17
|
-
---
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { toUint8Array } from "@smithy/util-utf8";
|
|
2
|
-
import { Writable } from "stream";
|
|
3
|
-
export class HashCalculator extends Writable {
|
|
4
|
-
hash;
|
|
5
|
-
constructor(hash, options) {
|
|
6
|
-
super(options);
|
|
7
|
-
this.hash = hash;
|
|
8
|
-
}
|
|
9
|
-
_write(chunk, encoding, callback) {
|
|
10
|
-
try {
|
|
11
|
-
this.hash.update(toUint8Array(chunk));
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
14
|
-
return callback(err);
|
|
15
|
-
}
|
|
16
|
-
callback();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createReadStream } from "fs";
|
|
2
|
-
import { HashCalculator } from "./HashCalculator";
|
|
3
|
-
export const fileStreamHasher = (hashCtor, fileStream) => new Promise((resolve, reject) => {
|
|
4
|
-
if (!isReadStream(fileStream)) {
|
|
5
|
-
reject(new Error("Unable to calculate hash for non-file streams."));
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const fileStreamTee = createReadStream(fileStream.path, {
|
|
9
|
-
start: fileStream.start,
|
|
10
|
-
end: fileStream.end,
|
|
11
|
-
});
|
|
12
|
-
const hash = new hashCtor();
|
|
13
|
-
const hashCalculator = new HashCalculator(hash);
|
|
14
|
-
fileStreamTee.pipe(hashCalculator);
|
|
15
|
-
fileStreamTee.on("error", (err) => {
|
|
16
|
-
hashCalculator.end();
|
|
17
|
-
reject(err);
|
|
18
|
-
});
|
|
19
|
-
hashCalculator.on("error", reject);
|
|
20
|
-
hashCalculator.on("finish", function () {
|
|
21
|
-
hash.digest().then(resolve).catch(reject);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
const isReadStream = (stream) => typeof stream.path === "string";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HashCalculator } from "./HashCalculator";
|
|
2
|
-
export const readableStreamHasher = (hashCtor, readableStream) => {
|
|
3
|
-
if (readableStream.readableFlowing !== null) {
|
|
4
|
-
throw new Error("Unable to calculate hash for flowing readable stream");
|
|
5
|
-
}
|
|
6
|
-
const hash = new hashCtor();
|
|
7
|
-
const hashCalculator = new HashCalculator(hash);
|
|
8
|
-
readableStream.pipe(hashCalculator);
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
readableStream.on("error", (err) => {
|
|
11
|
-
hashCalculator.end();
|
|
12
|
-
reject(err);
|
|
13
|
-
});
|
|
14
|
-
hashCalculator.on("error", reject);
|
|
15
|
-
hashCalculator.on("finish", () => {
|
|
16
|
-
hash.digest().then(resolve).catch(reject);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Checksum, Hash } from "@smithy/types";
|
|
2
|
-
import type { WritableOptions } from "stream";
|
|
3
|
-
import { Writable } from "stream";
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export declare class HashCalculator extends Writable {
|
|
8
|
-
readonly hash: Checksum | Hash;
|
|
9
|
-
constructor(hash: Checksum | Hash, options?: WritableOptions);
|
|
10
|
-
_write(chunk: Buffer, encoding: string, callback: (err?: Error) => void): void;
|
|
11
|
-
}
|