@loaders.gl/crypto 3.1.0-alpha.4 → 3.1.0-alpha.5
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/bundle.d.ts +1 -0
- package/dist/dist.min.js +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +11 -11
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/algorithms/crc32.js +18 -29
- package/dist/es5/lib/algorithms/crc32.js.map +1 -1
- package/dist/es5/lib/algorithms/crc32c.js +18 -30
- package/dist/es5/lib/algorithms/crc32c.js.map +1 -1
- package/dist/es5/lib/algorithms/md5-wasm.js +25 -36
- package/dist/es5/lib/algorithms/md5-wasm.js.map +1 -1
- package/dist/es5/lib/crc32-hash.js +39 -185
- package/dist/es5/lib/crc32-hash.js.map +1 -1
- package/dist/es5/lib/crc32c-hash.js +38 -184
- package/dist/es5/lib/crc32c-hash.js.map +1 -1
- package/dist/es5/lib/crypto-hash.js +49 -225
- package/dist/es5/lib/crypto-hash.js.map +1 -1
- package/dist/es5/lib/hash.js +21 -175
- package/dist/es5/lib/hash.js.map +1 -1
- package/dist/es5/lib/md5-hash.js +13 -71
- package/dist/es5/lib/md5-hash.js.map +1 -1
- package/dist/es5/lib/node-hash.js +33 -181
- package/dist/es5/lib/node-hash.js.map +1 -1
- package/dist/es5/lib/sha256-hash.js +7 -33
- package/dist/es5/lib/sha256-hash.js.map +1 -1
- package/dist/es5/lib/utils/base64-utils.js +13 -13
- package/dist/es5/lib/utils/base64-utils.js.map +1 -1
- package/dist/es5/lib/utils/digest-utils.js +2 -4
- package/dist/es5/lib/utils/digest-utils.js.map +1 -1
- package/dist/es5/workers/worker.js +17 -55
- package/dist/es5/workers/worker.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/utils/base64-utils.js +1 -1
- package/dist/esm/lib/utils/base64-utils.js.map +1 -1
- package/dist/esm/lib/utils/digest-utils.js +2 -2
- package/dist/esm/lib/utils/digest-utils.js.map +1 -1
- package/dist/esm/workers/worker.js +1 -1
- package/dist/esm/workers/worker.js.map +1 -1
- package/dist/index.d.ts +32 -0
- package/dist/lib/algorithms/crc32.d.ts +8 -0
- package/dist/lib/algorithms/crc32c.d.ts +10 -0
- package/dist/lib/algorithms/md5-wasm.d.ts +4 -0
- package/dist/lib/crc32-hash.d.ts +17 -0
- package/dist/lib/crc32c-hash.d.ts +21 -0
- package/dist/lib/crypto-hash.d.ts +31 -0
- package/dist/lib/hash.d.ts +21 -0
- package/dist/lib/md5-hash.d.ts +14 -0
- package/dist/lib/node-hash.d.ts +27 -0
- package/dist/lib/sha256-hash.d.ts +18 -0
- package/dist/lib/utils/base64-utils.d.ts +5 -0
- package/dist/lib/utils/digest-utils.d.ts +8 -0
- package/dist/types.d.ts +9 -0
- package/dist/worker.js +22 -22
- package/dist/worker.js.map +1 -1
- package/dist/workers/worker.d.ts +3 -0
- package/package.json +6 -5
|
@@ -7,207 +7,61 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.CRC32Hash = void 0;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
11
|
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
31
|
-
|
|
32
|
-
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
|
|
33
|
-
|
|
34
|
-
var _hash2 = require("./hash");
|
|
12
|
+
var _hash = require("./hash");
|
|
35
13
|
|
|
36
14
|
var _crc = _interopRequireDefault(require("./algorithms/crc32"));
|
|
37
15
|
|
|
38
16
|
var _digestUtils = require("./utils/digest-utils");
|
|
39
17
|
|
|
40
|
-
|
|
18
|
+
class CRC32Hash extends _hash.Hash {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", 'crc32');
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "_hash", void 0);
|
|
24
|
+
this.options = {
|
|
25
|
+
crypto: {},
|
|
26
|
+
...options
|
|
27
|
+
};
|
|
28
|
+
this._hash = new _crc.default();
|
|
29
|
+
this.hashBatches = this.hashBatches.bind(this);
|
|
30
|
+
}
|
|
41
31
|
|
|
42
|
-
|
|
32
|
+
async hash(input) {
|
|
33
|
+
return this.hashSync(input);
|
|
34
|
+
}
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
hashSync(input) {
|
|
37
|
+
this._hash.update(input);
|
|
45
38
|
|
|
46
|
-
|
|
39
|
+
const hashValue = this._hash.finalize();
|
|
47
40
|
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
42
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
43
|
+
return hash;
|
|
44
|
+
}
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
async *hashBatches(asyncIterator) {
|
|
47
|
+
var _this$options$crypto, _this$options$crypto$;
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
for await (const chunk of asyncIterator) {
|
|
50
|
+
this._hash.update(chunk);
|
|
55
51
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_this2.hashBatches = _this2.hashBatches.bind((0, _assertThisInitialized2.default)(_this2));
|
|
67
|
-
return _this2;
|
|
52
|
+
yield chunk;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const hashValue = this._hash.finalize();
|
|
56
|
+
|
|
57
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
58
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
59
|
+
(_this$options$crypto = this.options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
60
|
+
hash
|
|
61
|
+
});
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
key: "hash",
|
|
72
|
-
value: function () {
|
|
73
|
-
var _hash = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(input) {
|
|
74
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
75
|
-
while (1) {
|
|
76
|
-
switch (_context.prev = _context.next) {
|
|
77
|
-
case 0:
|
|
78
|
-
return _context.abrupt("return", this.hashSync(input));
|
|
79
|
-
|
|
80
|
-
case 1:
|
|
81
|
-
case "end":
|
|
82
|
-
return _context.stop();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}, _callee, this);
|
|
86
|
-
}));
|
|
87
|
-
|
|
88
|
-
function hash(_x) {
|
|
89
|
-
return _hash.apply(this, arguments);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return hash;
|
|
93
|
-
}()
|
|
94
|
-
}, {
|
|
95
|
-
key: "hashSync",
|
|
96
|
-
value: function hashSync(input) {
|
|
97
|
-
this._hash.update(input);
|
|
98
|
-
|
|
99
|
-
var hashValue = this._hash.finalize();
|
|
100
|
-
|
|
101
|
-
var hex = (0, _digestUtils.toHex)(hashValue);
|
|
102
|
-
var hash = (0, _digestUtils.hexToBase64)(hex);
|
|
103
|
-
return hash;
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
key: "hashBatches",
|
|
107
|
-
value: function hashBatches(asyncIterator) {
|
|
108
|
-
var _this = this;
|
|
109
|
-
|
|
110
|
-
return (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee2() {
|
|
111
|
-
var _this$options$crypto, _this$options$crypto$;
|
|
112
|
-
|
|
113
|
-
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, hashValue, hex, hash;
|
|
114
|
-
|
|
115
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
116
|
-
while (1) {
|
|
117
|
-
switch (_context2.prev = _context2.next) {
|
|
118
|
-
case 0:
|
|
119
|
-
_iteratorNormalCompletion = true;
|
|
120
|
-
_didIteratorError = false;
|
|
121
|
-
_context2.prev = 2;
|
|
122
|
-
_iterator = (0, _asyncIterator2.default)(asyncIterator);
|
|
123
|
-
|
|
124
|
-
case 4:
|
|
125
|
-
_context2.next = 6;
|
|
126
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
127
|
-
|
|
128
|
-
case 6:
|
|
129
|
-
_step = _context2.sent;
|
|
130
|
-
_iteratorNormalCompletion = _step.done;
|
|
131
|
-
_context2.next = 10;
|
|
132
|
-
return (0, _awaitAsyncGenerator2.default)(_step.value);
|
|
133
|
-
|
|
134
|
-
case 10:
|
|
135
|
-
_value = _context2.sent;
|
|
136
|
-
|
|
137
|
-
if (_iteratorNormalCompletion) {
|
|
138
|
-
_context2.next = 19;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
chunk = _value;
|
|
143
|
-
|
|
144
|
-
_this._hash.update(chunk);
|
|
145
|
-
|
|
146
|
-
_context2.next = 16;
|
|
147
|
-
return chunk;
|
|
148
|
-
|
|
149
|
-
case 16:
|
|
150
|
-
_iteratorNormalCompletion = true;
|
|
151
|
-
_context2.next = 4;
|
|
152
|
-
break;
|
|
153
|
-
|
|
154
|
-
case 19:
|
|
155
|
-
_context2.next = 25;
|
|
156
|
-
break;
|
|
157
|
-
|
|
158
|
-
case 21:
|
|
159
|
-
_context2.prev = 21;
|
|
160
|
-
_context2.t0 = _context2["catch"](2);
|
|
161
|
-
_didIteratorError = true;
|
|
162
|
-
_iteratorError = _context2.t0;
|
|
163
|
-
|
|
164
|
-
case 25:
|
|
165
|
-
_context2.prev = 25;
|
|
166
|
-
_context2.prev = 26;
|
|
167
|
-
|
|
168
|
-
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
|
|
169
|
-
_context2.next = 30;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
_context2.next = 30;
|
|
174
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
175
|
-
|
|
176
|
-
case 30:
|
|
177
|
-
_context2.prev = 30;
|
|
178
|
-
|
|
179
|
-
if (!_didIteratorError) {
|
|
180
|
-
_context2.next = 33;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
throw _iteratorError;
|
|
185
|
-
|
|
186
|
-
case 33:
|
|
187
|
-
return _context2.finish(30);
|
|
188
|
-
|
|
189
|
-
case 34:
|
|
190
|
-
return _context2.finish(25);
|
|
191
|
-
|
|
192
|
-
case 35:
|
|
193
|
-
hashValue = _this._hash.finalize();
|
|
194
|
-
hex = (0, _digestUtils.toHex)(hashValue);
|
|
195
|
-
hash = (0, _digestUtils.hexToBase64)(hex);
|
|
196
|
-
(_this$options$crypto = _this.options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
197
|
-
hash: hash
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
case 39:
|
|
201
|
-
case "end":
|
|
202
|
-
return _context2.stop();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}, _callee2, null, [[2, 21, 25, 35], [26,, 30, 34]]);
|
|
206
|
-
}))();
|
|
207
|
-
}
|
|
208
|
-
}]);
|
|
209
|
-
return CRC32Hash;
|
|
210
|
-
}(_hash2.Hash);
|
|
64
|
+
}
|
|
211
65
|
|
|
212
66
|
exports.CRC32Hash = CRC32Hash;
|
|
213
67
|
//# sourceMappingURL=crc32-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crc32-hash.ts"],"names":["CRC32Hash","options","crypto","_hash","CRC32","hashBatches","bind","input","hashSync","update","hashValue","finalize","hex","
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crc32-hash.ts"],"names":["CRC32Hash","Hash","constructor","options","crypto","_hash","CRC32","hashBatches","bind","hash","input","hashSync","update","hashValue","finalize","hex","asyncIterator","chunk","onEnd"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAKO,MAAMA,SAAN,SAAwBC,UAAxB,CAA6B;AAMlCC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxB;AADwB,gDALV,OAKU;AAAA;AAAA;AAExB,SAAKA,OAAL,GAAe;AAACC,MAAAA,MAAM,EAAE,EAAT;AAAa,SAAGD;AAAhB,KAAf;AACA,SAAKE,KAAL,GAAa,IAAIC,YAAJ,EAAb;AACA,SAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAsB,IAAtB,CAAnB;AACD;;AAMS,QAAJC,IAAI,CAACC,KAAD,EAAsC;AAC9C,WAAO,KAAKC,QAAL,CAAcD,KAAd,CAAP;AACD;;AAEDC,EAAAA,QAAQ,CAACD,KAAD,EAA6B;AACnC,SAAKL,KAAL,CAAWO,MAAX,CAAkBF,KAAlB;;AACA,UAAMG,SAAS,GAAG,KAAKR,KAAL,CAAWS,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,WAAON,IAAP;AACD;;AAEiB,SAAXF,WAAW,CAChBS,aADgB,EAEY;AAAA;;AAC5B,eAAW,MAAMC,KAAjB,IAA0BD,aAA1B,EAAyC;AACvC,WAAKX,KAAL,CAAWO,MAAX,CAAkBK,KAAlB;;AACA,YAAMA,KAAN;AACD;;AACD,UAAMJ,SAAS,GAAG,KAAKR,KAAL,CAAWS,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,iCAAKZ,OAAL,CAAaC,MAAb,uGAAqBc,KAArB,2GAA6B;AAACT,MAAAA;AAAD,KAA7B;AACD;;AAxCiC","sourcesContent":["// CRC32\nimport {Hash} from './hash';\nimport CRC32 from './algorithms/crc32';\nimport {toHex, hexToBase64} from './utils/digest-utils';\n\n/**\n * Calculates CRC32 Cryptographic Hash\n */\nexport class CRC32Hash extends Hash {\n readonly name = 'crc32';\n\n options;\n private _hash: CRC32;\n\n constructor(options = {}) {\n super();\n this.options = {crypto: {}, ...options};\n this._hash = new CRC32();\n this.hashBatches = this.hashBatches.bind(this);\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n return this.hashSync(input);\n }\n\n hashSync(input: ArrayBuffer): string {\n this._hash.update(input);\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n return hash;\n }\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n for await (const chunk of asyncIterator) {\n this._hash.update(chunk);\n yield chunk;\n }\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n this.options.crypto?.onEnd?.({hash});\n }\n}\n"],"file":"crc32-hash.js"}
|
|
@@ -7,206 +7,60 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.CRC32CHash = void 0;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
11
|
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
|
|
31
|
-
|
|
32
|
-
var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator"));
|
|
33
|
-
|
|
34
|
-
var _hash2 = require("./hash");
|
|
12
|
+
var _hash = require("./hash");
|
|
35
13
|
|
|
36
14
|
var _crc32c = _interopRequireDefault(require("./algorithms/crc32c"));
|
|
37
15
|
|
|
38
16
|
var _digestUtils = require("./utils/digest-utils");
|
|
39
17
|
|
|
40
|
-
|
|
18
|
+
class CRC32CHash extends _hash.Hash {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "name", 'crc32c');
|
|
22
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "_hash", void 0);
|
|
24
|
+
this.options = {
|
|
25
|
+
crypto: {},
|
|
26
|
+
...options
|
|
27
|
+
};
|
|
28
|
+
this._hash = new _crc32c.default(options);
|
|
29
|
+
}
|
|
41
30
|
|
|
42
|
-
|
|
31
|
+
async hash(input) {
|
|
32
|
+
return this.hashSync(input);
|
|
33
|
+
}
|
|
43
34
|
|
|
44
|
-
|
|
35
|
+
hashSync(input) {
|
|
36
|
+
this._hash.update(input);
|
|
45
37
|
|
|
46
|
-
|
|
38
|
+
const hashValue = this._hash.finalize();
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
41
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
42
|
+
return hash;
|
|
43
|
+
}
|
|
50
44
|
|
|
51
|
-
|
|
45
|
+
async *hashBatches(asyncIterator) {
|
|
46
|
+
var _this$options$crypto, _this$options$crypto$;
|
|
52
47
|
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
for await (const chunk of asyncIterator) {
|
|
49
|
+
this._hash.update(chunk);
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return _this2;
|
|
51
|
+
yield chunk;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const hashValue = this._hash.finalize();
|
|
55
|
+
|
|
56
|
+
const hex = (0, _digestUtils.toHex)(hashValue);
|
|
57
|
+
const hash = (0, _digestUtils.hexToBase64)(hex);
|
|
58
|
+
(_this$options$crypto = this.options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
59
|
+
hash
|
|
60
|
+
});
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
|
|
70
|
-
key: "hash",
|
|
71
|
-
value: function () {
|
|
72
|
-
var _hash = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(input) {
|
|
73
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
74
|
-
while (1) {
|
|
75
|
-
switch (_context.prev = _context.next) {
|
|
76
|
-
case 0:
|
|
77
|
-
return _context.abrupt("return", this.hashSync(input));
|
|
78
|
-
|
|
79
|
-
case 1:
|
|
80
|
-
case "end":
|
|
81
|
-
return _context.stop();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, _callee, this);
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
function hash(_x) {
|
|
88
|
-
return _hash.apply(this, arguments);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return hash;
|
|
92
|
-
}()
|
|
93
|
-
}, {
|
|
94
|
-
key: "hashSync",
|
|
95
|
-
value: function hashSync(input) {
|
|
96
|
-
this._hash.update(input);
|
|
97
|
-
|
|
98
|
-
var hashValue = this._hash.finalize();
|
|
99
|
-
|
|
100
|
-
var hex = (0, _digestUtils.toHex)(hashValue);
|
|
101
|
-
var hash = (0, _digestUtils.hexToBase64)(hex);
|
|
102
|
-
return hash;
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
key: "hashBatches",
|
|
106
|
-
value: function hashBatches(asyncIterator) {
|
|
107
|
-
var _this = this;
|
|
108
|
-
|
|
109
|
-
return (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee2() {
|
|
110
|
-
var _this$options$crypto, _this$options$crypto$;
|
|
111
|
-
|
|
112
|
-
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, hashValue, hex, hash;
|
|
113
|
-
|
|
114
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
115
|
-
while (1) {
|
|
116
|
-
switch (_context2.prev = _context2.next) {
|
|
117
|
-
case 0:
|
|
118
|
-
_iteratorNormalCompletion = true;
|
|
119
|
-
_didIteratorError = false;
|
|
120
|
-
_context2.prev = 2;
|
|
121
|
-
_iterator = (0, _asyncIterator2.default)(asyncIterator);
|
|
122
|
-
|
|
123
|
-
case 4:
|
|
124
|
-
_context2.next = 6;
|
|
125
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
126
|
-
|
|
127
|
-
case 6:
|
|
128
|
-
_step = _context2.sent;
|
|
129
|
-
_iteratorNormalCompletion = _step.done;
|
|
130
|
-
_context2.next = 10;
|
|
131
|
-
return (0, _awaitAsyncGenerator2.default)(_step.value);
|
|
132
|
-
|
|
133
|
-
case 10:
|
|
134
|
-
_value = _context2.sent;
|
|
135
|
-
|
|
136
|
-
if (_iteratorNormalCompletion) {
|
|
137
|
-
_context2.next = 19;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
chunk = _value;
|
|
142
|
-
|
|
143
|
-
_this._hash.update(chunk);
|
|
144
|
-
|
|
145
|
-
_context2.next = 16;
|
|
146
|
-
return chunk;
|
|
147
|
-
|
|
148
|
-
case 16:
|
|
149
|
-
_iteratorNormalCompletion = true;
|
|
150
|
-
_context2.next = 4;
|
|
151
|
-
break;
|
|
152
|
-
|
|
153
|
-
case 19:
|
|
154
|
-
_context2.next = 25;
|
|
155
|
-
break;
|
|
156
|
-
|
|
157
|
-
case 21:
|
|
158
|
-
_context2.prev = 21;
|
|
159
|
-
_context2.t0 = _context2["catch"](2);
|
|
160
|
-
_didIteratorError = true;
|
|
161
|
-
_iteratorError = _context2.t0;
|
|
162
|
-
|
|
163
|
-
case 25:
|
|
164
|
-
_context2.prev = 25;
|
|
165
|
-
_context2.prev = 26;
|
|
166
|
-
|
|
167
|
-
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
|
|
168
|
-
_context2.next = 30;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
_context2.next = 30;
|
|
173
|
-
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
174
|
-
|
|
175
|
-
case 30:
|
|
176
|
-
_context2.prev = 30;
|
|
177
|
-
|
|
178
|
-
if (!_didIteratorError) {
|
|
179
|
-
_context2.next = 33;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
throw _iteratorError;
|
|
184
|
-
|
|
185
|
-
case 33:
|
|
186
|
-
return _context2.finish(30);
|
|
187
|
-
|
|
188
|
-
case 34:
|
|
189
|
-
return _context2.finish(25);
|
|
190
|
-
|
|
191
|
-
case 35:
|
|
192
|
-
hashValue = _this._hash.finalize();
|
|
193
|
-
hex = (0, _digestUtils.toHex)(hashValue);
|
|
194
|
-
hash = (0, _digestUtils.hexToBase64)(hex);
|
|
195
|
-
(_this$options$crypto = _this.options.crypto) === null || _this$options$crypto === void 0 ? void 0 : (_this$options$crypto$ = _this$options$crypto.onEnd) === null || _this$options$crypto$ === void 0 ? void 0 : _this$options$crypto$.call(_this$options$crypto, {
|
|
196
|
-
hash: hash
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
case 39:
|
|
200
|
-
case "end":
|
|
201
|
-
return _context2.stop();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, _callee2, null, [[2, 21, 25, 35], [26,, 30, 34]]);
|
|
205
|
-
}))();
|
|
206
|
-
}
|
|
207
|
-
}]);
|
|
208
|
-
return CRC32CHash;
|
|
209
|
-
}(_hash2.Hash);
|
|
63
|
+
}
|
|
210
64
|
|
|
211
65
|
exports.CRC32CHash = CRC32CHash;
|
|
212
66
|
//# sourceMappingURL=crc32c-hash.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/crc32c-hash.ts"],"names":["CRC32CHash","options","crypto","_hash","CRC32C","input","hashSync","update","hashValue","finalize","hex","
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/crc32c-hash.ts"],"names":["CRC32CHash","Hash","constructor","options","crypto","_hash","CRC32C","hash","input","hashSync","update","hashValue","finalize","hex","hashBatches","asyncIterator","chunk","onEnd"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;AAKO,MAAMA,UAAN,SAAyBC,UAAzB,CAA8B;AAUnCC,EAAAA,WAAW,CAACC,OAAO,GAAG,EAAX,EAAe;AACxB;AADwB,gDATV,QASU;AAAA;AAAA;AAExB,SAAKA,OAAL,GAAe;AAACC,MAAAA,MAAM,EAAE,EAAT;AAAa,SAAGD;AAAhB,KAAf;AACA,SAAKE,KAAL,GAAa,IAAIC,eAAJ,CAAWH,OAAX,CAAb;AACD;;AAMS,QAAJI,IAAI,CAACC,KAAD,EAAsC;AAC9C,WAAO,KAAKC,QAAL,CAAcD,KAAd,CAAP;AACD;;AAEDC,EAAAA,QAAQ,CAACD,KAAD,EAA6B;AACnC,SAAKH,KAAL,CAAWK,MAAX,CAAkBF,KAAlB;;AACA,UAAMG,SAAS,GAAG,KAAKN,KAAL,CAAWO,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,WAAON,IAAP;AACD;;AAIiB,SAAXO,WAAW,CAChBC,aADgB,EAEY;AAAA;;AAC5B,eAAW,MAAMC,KAAjB,IAA0BD,aAA1B,EAAyC;AACvC,WAAKV,KAAL,CAAWK,MAAX,CAAkBM,KAAlB;;AACA,YAAMA,KAAN;AACD;;AACD,UAAML,SAAS,GAAG,KAAKN,KAAL,CAAWO,QAAX,EAAlB;;AACA,UAAMC,GAAG,GAAG,wBAAMF,SAAN,CAAZ;AACA,UAAMJ,IAAI,GAAG,8BAAYM,GAAZ,CAAb;AACA,iCAAKV,OAAL,CAAaC,MAAb,uGAAqBa,KAArB,2GAA6B;AAACV,MAAAA;AAAD,KAA7B;AACD;;AA7CkC","sourcesContent":["// CRC32c\nimport {Hash} from './hash';\nimport CRC32C from './algorithms/crc32c';\nimport {toHex, hexToBase64} from './utils/digest-utils';\n\n/**\n * A transform that calculates CRC32c Hash\n */\nexport class CRC32CHash extends Hash {\n readonly name = 'crc32c';\n\n options;\n private _hash: CRC32C;\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n constructor(options = {}) {\n super();\n this.options = {crypto: {}, ...options};\n this._hash = new CRC32C(options);\n }\n\n /**\n * Atomic hash calculation\n * @returns base64 encoded hash\n */\n async hash(input: ArrayBuffer): Promise<string> {\n return this.hashSync(input);\n }\n\n hashSync(input: ArrayBuffer): string {\n this._hash.update(input);\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n return hash;\n }\n\n // runInBatches inherited\n\n async *hashBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n ): AsyncIterable<ArrayBuffer> {\n for await (const chunk of asyncIterator) {\n this._hash.update(chunk);\n yield chunk;\n }\n const hashValue = this._hash.finalize();\n const hex = toHex(hashValue);\n const hash = hexToBase64(hex);\n this.options.crypto?.onEnd?.({hash});\n }\n}\n"],"file":"crc32c-hash.js"}
|