@aws-sdk/sha256-tree-hash 3.901.0 → 3.914.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.
Files changed (2) hide show
  1. package/dist-cjs/index.js +75 -123
  2. package/package.json +3 -3
package/dist-cjs/index.js CHANGED
@@ -1,132 +1,84 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
20
2
 
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- TreeHash: () => TreeHash
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
- var MiB = 1048576;
28
- var TreeHash = class {
29
- /**
30
- * Initializes a TreeHash.
31
- * @param Sha256 A Sha256 hash constructor.
32
- */
33
- constructor(Sha256, fromUtf8) {
34
- this.Sha256 = Sha256;
35
- this.fromUtf8 = fromUtf8;
36
- }
37
- static {
38
- __name(this, "TreeHash");
39
- }
40
- buffer;
41
- collectedHashDigests = [];
42
- /**
43
- * Generates Sha256 hashes from 1 MiB chunks of the
44
- * internal buffer.
45
- * Will set the internal buffer to any bytes remaining
46
- * that is less than 1 MiB.
47
- */
48
- hashBuffer() {
49
- if (!this.buffer) {
50
- return;
3
+ const MiB = 1048576;
4
+ class TreeHash {
5
+ Sha256;
6
+ fromUtf8;
7
+ buffer;
8
+ collectedHashDigests = [];
9
+ constructor(Sha256, fromUtf8) {
10
+ this.Sha256 = Sha256;
11
+ this.fromUtf8 = fromUtf8;
51
12
  }
52
- let remainingSize = this.buffer.byteLength;
53
- while (remainingSize >= MiB) {
54
- const hash = new this.Sha256();
55
- hash.update(this.buffer.subarray(0, MiB));
56
- this.collectedHashDigests.push(hash.digest());
57
- this.buffer = this.buffer.subarray(MiB);
58
- remainingSize = this.buffer.byteLength;
59
- }
60
- }
61
- /**
62
- * Updates the tree hash with byte data.
63
- * @param data Byte data to apply to the tree hash.
64
- */
65
- update(data) {
66
- const chunk = this.convertToBuffer(data);
67
- if (!this.buffer) {
68
- this.buffer = chunk;
69
- } else {
70
- const totalSize = this.buffer.byteLength + chunk.byteLength;
71
- const tempBuffer = new Uint8Array(totalSize);
72
- tempBuffer.set(this.buffer);
73
- tempBuffer.set(chunk, this.buffer.byteLength);
74
- this.buffer = tempBuffer;
13
+ hashBuffer() {
14
+ if (!this.buffer) {
15
+ return;
16
+ }
17
+ let remainingSize = this.buffer.byteLength;
18
+ while (remainingSize >= MiB) {
19
+ const hash = new this.Sha256();
20
+ hash.update(this.buffer.subarray(0, MiB));
21
+ this.collectedHashDigests.push(hash.digest());
22
+ this.buffer = this.buffer.subarray(MiB);
23
+ remainingSize = this.buffer.byteLength;
24
+ }
75
25
  }
76
- this.hashBuffer();
77
- }
78
- /**
79
- * Calculates the digest for the tree hash.
80
- */
81
- async digest() {
82
- let collectedHashDigests = this.collectedHashDigests;
83
- this.collectedHashDigests = [];
84
- if (this.buffer && this.buffer.byteLength > 0) {
85
- const smallHash = new this.Sha256();
86
- smallHash.update(this.buffer);
87
- collectedHashDigests.push(smallHash.digest());
88
- this.buffer = void 0;
26
+ update(data) {
27
+ const chunk = this.convertToBuffer(data);
28
+ if (!this.buffer) {
29
+ this.buffer = chunk;
30
+ }
31
+ else {
32
+ const totalSize = this.buffer.byteLength + chunk.byteLength;
33
+ const tempBuffer = new Uint8Array(totalSize);
34
+ tempBuffer.set(this.buffer);
35
+ tempBuffer.set(chunk, this.buffer.byteLength);
36
+ this.buffer = tempBuffer;
37
+ }
38
+ this.hashBuffer();
89
39
  }
90
- while (collectedHashDigests.length > 1) {
91
- const higherLevelHashDigests = [];
92
- for (let i = 0; i < collectedHashDigests.length; i += 2) {
93
- if (i + 1 < collectedHashDigests.length) {
94
- const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]);
95
- const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
96
- chunk.set(digest1);
97
- chunk.set(digest2, digest1.byteLength);
98
- const hash = new this.Sha256();
99
- hash.update(chunk);
100
- higherLevelHashDigests.push(hash.digest());
101
- } else {
102
- higherLevelHashDigests.push(collectedHashDigests[i]);
40
+ async digest() {
41
+ let collectedHashDigests = this.collectedHashDigests;
42
+ this.collectedHashDigests = [];
43
+ if (this.buffer && this.buffer.byteLength > 0) {
44
+ const smallHash = new this.Sha256();
45
+ smallHash.update(this.buffer);
46
+ collectedHashDigests.push(smallHash.digest());
47
+ this.buffer = void 0;
103
48
  }
104
- }
105
- collectedHashDigests = higherLevelHashDigests;
49
+ while (collectedHashDigests.length > 1) {
50
+ const higherLevelHashDigests = [];
51
+ for (let i = 0; i < collectedHashDigests.length; i += 2) {
52
+ if (i + 1 < collectedHashDigests.length) {
53
+ const [digest1, digest2] = await Promise.all([collectedHashDigests[i], collectedHashDigests[i + 1]]);
54
+ const chunk = new Uint8Array(digest1.byteLength + digest2.byteLength);
55
+ chunk.set(digest1);
56
+ chunk.set(digest2, digest1.byteLength);
57
+ const hash = new this.Sha256();
58
+ hash.update(chunk);
59
+ higherLevelHashDigests.push(hash.digest());
60
+ }
61
+ else {
62
+ higherLevelHashDigests.push(collectedHashDigests[i]);
63
+ }
64
+ }
65
+ collectedHashDigests = higherLevelHashDigests;
66
+ }
67
+ return collectedHashDigests[0];
106
68
  }
107
- return collectedHashDigests[0];
108
- }
109
- /**
110
- * Converts source data into a Uint8Array.
111
- * @param data Data to convert to a Uint8Array.
112
- */
113
- convertToBuffer(data) {
114
- if (typeof data === "string") {
115
- return this.fromUtf8(data);
69
+ convertToBuffer(data) {
70
+ if (typeof data === "string") {
71
+ return this.fromUtf8(data);
72
+ }
73
+ if (ArrayBuffer.isView(data)) {
74
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
75
+ }
76
+ return new Uint8Array(data);
116
77
  }
117
- if (ArrayBuffer.isView(data)) {
118
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
78
+ reset() {
79
+ this.buffer = undefined;
80
+ this.collectedHashDigests = [];
119
81
  }
120
- return new Uint8Array(data);
121
- }
122
- reset() {
123
- this.buffer = void 0;
124
- this.collectedHashDigests = [];
125
- }
126
- };
127
- // Annotate the CommonJS export names for ESM import in node:
128
-
129
- 0 && (module.exports = {
130
- TreeHash
131
- });
82
+ }
132
83
 
84
+ exports.TreeHash = TreeHash;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/sha256-tree-hash",
3
- "version": "3.901.0",
3
+ "version": "3.914.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline sha256-tree-hash",
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@aws-sdk/types": "3.901.0",
26
- "@smithy/types": "^4.6.0",
25
+ "@aws-sdk/types": "3.914.0",
26
+ "@smithy/types": "^4.8.0",
27
27
  "tslib": "^2.6.2"
28
28
  },
29
29
  "devDependencies": {