@vunk/form 1.1.85 → 1.2.2

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.
@@ -0,0 +1,774 @@
1
+ 'use strict';
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ var sparkMd5 = {exports: {}};
8
+
9
+ (function (module, exports) {
10
+ (function (factory) {
11
+ {
12
+ // Node/CommonJS
13
+ module.exports = factory();
14
+ }
15
+ }(function (undefined$1) {
16
+
17
+ /*
18
+ * Fastest md5 implementation around (JKM md5).
19
+ * Credits: Joseph Myers
20
+ *
21
+ * @see http://www.myersdaily.org/joseph/javascript/md5-text.html
22
+ * @see http://jsperf.com/md5-shootout/7
23
+ */
24
+
25
+ /* this function is much faster,
26
+ so if possible we use it. Some IEs
27
+ are the only ones I know of that
28
+ need the idiotic second function,
29
+ generated by an if clause. */
30
+ var hex_chr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
31
+
32
+ function md5cycle(x, k) {
33
+ var a = x[0],
34
+ b = x[1],
35
+ c = x[2],
36
+ d = x[3];
37
+
38
+ a += (b & c | ~b & d) + k[0] - 680876936 | 0;
39
+ a = (a << 7 | a >>> 25) + b | 0;
40
+ d += (a & b | ~a & c) + k[1] - 389564586 | 0;
41
+ d = (d << 12 | d >>> 20) + a | 0;
42
+ c += (d & a | ~d & b) + k[2] + 606105819 | 0;
43
+ c = (c << 17 | c >>> 15) + d | 0;
44
+ b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
45
+ b = (b << 22 | b >>> 10) + c | 0;
46
+ a += (b & c | ~b & d) + k[4] - 176418897 | 0;
47
+ a = (a << 7 | a >>> 25) + b | 0;
48
+ d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
49
+ d = (d << 12 | d >>> 20) + a | 0;
50
+ c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
51
+ c = (c << 17 | c >>> 15) + d | 0;
52
+ b += (c & d | ~c & a) + k[7] - 45705983 | 0;
53
+ b = (b << 22 | b >>> 10) + c | 0;
54
+ a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
55
+ a = (a << 7 | a >>> 25) + b | 0;
56
+ d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
57
+ d = (d << 12 | d >>> 20) + a | 0;
58
+ c += (d & a | ~d & b) + k[10] - 42063 | 0;
59
+ c = (c << 17 | c >>> 15) + d | 0;
60
+ b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
61
+ b = (b << 22 | b >>> 10) + c | 0;
62
+ a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
63
+ a = (a << 7 | a >>> 25) + b | 0;
64
+ d += (a & b | ~a & c) + k[13] - 40341101 | 0;
65
+ d = (d << 12 | d >>> 20) + a | 0;
66
+ c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
67
+ c = (c << 17 | c >>> 15) + d | 0;
68
+ b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
69
+ b = (b << 22 | b >>> 10) + c | 0;
70
+
71
+ a += (b & d | c & ~d) + k[1] - 165796510 | 0;
72
+ a = (a << 5 | a >>> 27) + b | 0;
73
+ d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
74
+ d = (d << 9 | d >>> 23) + a | 0;
75
+ c += (d & b | a & ~b) + k[11] + 643717713 | 0;
76
+ c = (c << 14 | c >>> 18) + d | 0;
77
+ b += (c & a | d & ~a) + k[0] - 373897302 | 0;
78
+ b = (b << 20 | b >>> 12) + c | 0;
79
+ a += (b & d | c & ~d) + k[5] - 701558691 | 0;
80
+ a = (a << 5 | a >>> 27) + b | 0;
81
+ d += (a & c | b & ~c) + k[10] + 38016083 | 0;
82
+ d = (d << 9 | d >>> 23) + a | 0;
83
+ c += (d & b | a & ~b) + k[15] - 660478335 | 0;
84
+ c = (c << 14 | c >>> 18) + d | 0;
85
+ b += (c & a | d & ~a) + k[4] - 405537848 | 0;
86
+ b = (b << 20 | b >>> 12) + c | 0;
87
+ a += (b & d | c & ~d) + k[9] + 568446438 | 0;
88
+ a = (a << 5 | a >>> 27) + b | 0;
89
+ d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
90
+ d = (d << 9 | d >>> 23) + a | 0;
91
+ c += (d & b | a & ~b) + k[3] - 187363961 | 0;
92
+ c = (c << 14 | c >>> 18) + d | 0;
93
+ b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
94
+ b = (b << 20 | b >>> 12) + c | 0;
95
+ a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
96
+ a = (a << 5 | a >>> 27) + b | 0;
97
+ d += (a & c | b & ~c) + k[2] - 51403784 | 0;
98
+ d = (d << 9 | d >>> 23) + a | 0;
99
+ c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
100
+ c = (c << 14 | c >>> 18) + d | 0;
101
+ b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
102
+ b = (b << 20 | b >>> 12) + c | 0;
103
+
104
+ a += (b ^ c ^ d) + k[5] - 378558 | 0;
105
+ a = (a << 4 | a >>> 28) + b | 0;
106
+ d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
107
+ d = (d << 11 | d >>> 21) + a | 0;
108
+ c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
109
+ c = (c << 16 | c >>> 16) + d | 0;
110
+ b += (c ^ d ^ a) + k[14] - 35309556 | 0;
111
+ b = (b << 23 | b >>> 9) + c | 0;
112
+ a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
113
+ a = (a << 4 | a >>> 28) + b | 0;
114
+ d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
115
+ d = (d << 11 | d >>> 21) + a | 0;
116
+ c += (d ^ a ^ b) + k[7] - 155497632 | 0;
117
+ c = (c << 16 | c >>> 16) + d | 0;
118
+ b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
119
+ b = (b << 23 | b >>> 9) + c | 0;
120
+ a += (b ^ c ^ d) + k[13] + 681279174 | 0;
121
+ a = (a << 4 | a >>> 28) + b | 0;
122
+ d += (a ^ b ^ c) + k[0] - 358537222 | 0;
123
+ d = (d << 11 | d >>> 21) + a | 0;
124
+ c += (d ^ a ^ b) + k[3] - 722521979 | 0;
125
+ c = (c << 16 | c >>> 16) + d | 0;
126
+ b += (c ^ d ^ a) + k[6] + 76029189 | 0;
127
+ b = (b << 23 | b >>> 9) + c | 0;
128
+ a += (b ^ c ^ d) + k[9] - 640364487 | 0;
129
+ a = (a << 4 | a >>> 28) + b | 0;
130
+ d += (a ^ b ^ c) + k[12] - 421815835 | 0;
131
+ d = (d << 11 | d >>> 21) + a | 0;
132
+ c += (d ^ a ^ b) + k[15] + 530742520 | 0;
133
+ c = (c << 16 | c >>> 16) + d | 0;
134
+ b += (c ^ d ^ a) + k[2] - 995338651 | 0;
135
+ b = (b << 23 | b >>> 9) + c | 0;
136
+
137
+ a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
138
+ a = (a << 6 | a >>> 26) + b | 0;
139
+ d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
140
+ d = (d << 10 | d >>> 22) + a | 0;
141
+ c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
142
+ c = (c << 15 | c >>> 17) + d | 0;
143
+ b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
144
+ b = (b << 21 |b >>> 11) + c | 0;
145
+ a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
146
+ a = (a << 6 | a >>> 26) + b | 0;
147
+ d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
148
+ d = (d << 10 | d >>> 22) + a | 0;
149
+ c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
150
+ c = (c << 15 | c >>> 17) + d | 0;
151
+ b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
152
+ b = (b << 21 |b >>> 11) + c | 0;
153
+ a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
154
+ a = (a << 6 | a >>> 26) + b | 0;
155
+ d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
156
+ d = (d << 10 | d >>> 22) + a | 0;
157
+ c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
158
+ c = (c << 15 | c >>> 17) + d | 0;
159
+ b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
160
+ b = (b << 21 |b >>> 11) + c | 0;
161
+ a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
162
+ a = (a << 6 | a >>> 26) + b | 0;
163
+ d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
164
+ d = (d << 10 | d >>> 22) + a | 0;
165
+ c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
166
+ c = (c << 15 | c >>> 17) + d | 0;
167
+ b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
168
+ b = (b << 21 | b >>> 11) + c | 0;
169
+
170
+ x[0] = a + x[0] | 0;
171
+ x[1] = b + x[1] | 0;
172
+ x[2] = c + x[2] | 0;
173
+ x[3] = d + x[3] | 0;
174
+ }
175
+
176
+ function md5blk(s) {
177
+ var md5blks = [],
178
+ i; /* Andy King said do it this way. */
179
+
180
+ for (i = 0; i < 64; i += 4) {
181
+ md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
182
+ }
183
+ return md5blks;
184
+ }
185
+
186
+ function md5blk_array(a) {
187
+ var md5blks = [],
188
+ i; /* Andy King said do it this way. */
189
+
190
+ for (i = 0; i < 64; i += 4) {
191
+ md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
192
+ }
193
+ return md5blks;
194
+ }
195
+
196
+ function md51(s) {
197
+ var n = s.length,
198
+ state = [1732584193, -271733879, -1732584194, 271733878],
199
+ i,
200
+ length,
201
+ tail,
202
+ tmp,
203
+ lo,
204
+ hi;
205
+
206
+ for (i = 64; i <= n; i += 64) {
207
+ md5cycle(state, md5blk(s.substring(i - 64, i)));
208
+ }
209
+ s = s.substring(i - 64);
210
+ length = s.length;
211
+ tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
212
+ for (i = 0; i < length; i += 1) {
213
+ tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
214
+ }
215
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
216
+ if (i > 55) {
217
+ md5cycle(state, tail);
218
+ for (i = 0; i < 16; i += 1) {
219
+ tail[i] = 0;
220
+ }
221
+ }
222
+
223
+ // Beware that the final length might not fit in 32 bits so we take care of that
224
+ tmp = n * 8;
225
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
226
+ lo = parseInt(tmp[2], 16);
227
+ hi = parseInt(tmp[1], 16) || 0;
228
+
229
+ tail[14] = lo;
230
+ tail[15] = hi;
231
+
232
+ md5cycle(state, tail);
233
+ return state;
234
+ }
235
+
236
+ function md51_array(a) {
237
+ var n = a.length,
238
+ state = [1732584193, -271733879, -1732584194, 271733878],
239
+ i,
240
+ length,
241
+ tail,
242
+ tmp,
243
+ lo,
244
+ hi;
245
+
246
+ for (i = 64; i <= n; i += 64) {
247
+ md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
248
+ }
249
+
250
+ // Not sure if it is a bug, however IE10 will always produce a sub array of length 1
251
+ // containing the last element of the parent array if the sub array specified starts
252
+ // beyond the length of the parent array - weird.
253
+ // https://connect.microsoft.com/IE/feedback/details/771452/typed-array-subarray-issue
254
+ a = (i - 64) < n ? a.subarray(i - 64) : new Uint8Array(0);
255
+
256
+ length = a.length;
257
+ tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
258
+ for (i = 0; i < length; i += 1) {
259
+ tail[i >> 2] |= a[i] << ((i % 4) << 3);
260
+ }
261
+
262
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
263
+ if (i > 55) {
264
+ md5cycle(state, tail);
265
+ for (i = 0; i < 16; i += 1) {
266
+ tail[i] = 0;
267
+ }
268
+ }
269
+
270
+ // Beware that the final length might not fit in 32 bits so we take care of that
271
+ tmp = n * 8;
272
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
273
+ lo = parseInt(tmp[2], 16);
274
+ hi = parseInt(tmp[1], 16) || 0;
275
+
276
+ tail[14] = lo;
277
+ tail[15] = hi;
278
+
279
+ md5cycle(state, tail);
280
+
281
+ return state;
282
+ }
283
+
284
+ function rhex(n) {
285
+ var s = '',
286
+ j;
287
+ for (j = 0; j < 4; j += 1) {
288
+ s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F];
289
+ }
290
+ return s;
291
+ }
292
+
293
+ function hex(x) {
294
+ var i;
295
+ for (i = 0; i < x.length; i += 1) {
296
+ x[i] = rhex(x[i]);
297
+ }
298
+ return x.join('');
299
+ }
300
+
301
+ // In some cases the fast add32 function cannot be used..
302
+ if (hex(md51('hello')) !== '5d41402abc4b2a76b9719d911017c592') ;
303
+
304
+ // ---------------------------------------------------
305
+
306
+ /**
307
+ * ArrayBuffer slice polyfill.
308
+ *
309
+ * @see https://github.com/ttaubert/node-arraybuffer-slice
310
+ */
311
+
312
+ if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
313
+ (function () {
314
+ function clamp(val, length) {
315
+ val = (val | 0) || 0;
316
+
317
+ if (val < 0) {
318
+ return Math.max(val + length, 0);
319
+ }
320
+
321
+ return Math.min(val, length);
322
+ }
323
+
324
+ ArrayBuffer.prototype.slice = function (from, to) {
325
+ var length = this.byteLength,
326
+ begin = clamp(from, length),
327
+ end = length,
328
+ num,
329
+ target,
330
+ targetArray,
331
+ sourceArray;
332
+
333
+ if (to !== undefined$1) {
334
+ end = clamp(to, length);
335
+ }
336
+
337
+ if (begin > end) {
338
+ return new ArrayBuffer(0);
339
+ }
340
+
341
+ num = end - begin;
342
+ target = new ArrayBuffer(num);
343
+ targetArray = new Uint8Array(target);
344
+
345
+ sourceArray = new Uint8Array(this, begin, num);
346
+ targetArray.set(sourceArray);
347
+
348
+ return target;
349
+ };
350
+ })();
351
+ }
352
+
353
+ // ---------------------------------------------------
354
+
355
+ /**
356
+ * Helpers.
357
+ */
358
+
359
+ function toUtf8(str) {
360
+ if (/[\u0080-\uFFFF]/.test(str)) {
361
+ str = unescape(encodeURIComponent(str));
362
+ }
363
+
364
+ return str;
365
+ }
366
+
367
+ function utf8Str2ArrayBuffer(str, returnUInt8Array) {
368
+ var length = str.length,
369
+ buff = new ArrayBuffer(length),
370
+ arr = new Uint8Array(buff),
371
+ i;
372
+
373
+ for (i = 0; i < length; i += 1) {
374
+ arr[i] = str.charCodeAt(i);
375
+ }
376
+
377
+ return returnUInt8Array ? arr : buff;
378
+ }
379
+
380
+ function arrayBuffer2Utf8Str(buff) {
381
+ return String.fromCharCode.apply(null, new Uint8Array(buff));
382
+ }
383
+
384
+ function concatenateArrayBuffers(first, second, returnUInt8Array) {
385
+ var result = new Uint8Array(first.byteLength + second.byteLength);
386
+
387
+ result.set(new Uint8Array(first));
388
+ result.set(new Uint8Array(second), first.byteLength);
389
+
390
+ return result ;
391
+ }
392
+
393
+ function hexToBinaryString(hex) {
394
+ var bytes = [],
395
+ length = hex.length,
396
+ x;
397
+
398
+ for (x = 0; x < length - 1; x += 2) {
399
+ bytes.push(parseInt(hex.substr(x, 2), 16));
400
+ }
401
+
402
+ return String.fromCharCode.apply(String, bytes);
403
+ }
404
+
405
+ // ---------------------------------------------------
406
+
407
+ /**
408
+ * SparkMD5 OOP implementation.
409
+ *
410
+ * Use this class to perform an incremental md5, otherwise use the
411
+ * static methods instead.
412
+ */
413
+
414
+ function SparkMD5() {
415
+ // call reset to init the instance
416
+ this.reset();
417
+ }
418
+
419
+ /**
420
+ * Appends a string.
421
+ * A conversion will be applied if an utf8 string is detected.
422
+ *
423
+ * @param {String} str The string to be appended
424
+ *
425
+ * @return {SparkMD5} The instance itself
426
+ */
427
+ SparkMD5.prototype.append = function (str) {
428
+ // Converts the string to utf8 bytes if necessary
429
+ // Then append as binary
430
+ this.appendBinary(toUtf8(str));
431
+
432
+ return this;
433
+ };
434
+
435
+ /**
436
+ * Appends a binary string.
437
+ *
438
+ * @param {String} contents The binary string to be appended
439
+ *
440
+ * @return {SparkMD5} The instance itself
441
+ */
442
+ SparkMD5.prototype.appendBinary = function (contents) {
443
+ this._buff += contents;
444
+ this._length += contents.length;
445
+
446
+ var length = this._buff.length,
447
+ i;
448
+
449
+ for (i = 64; i <= length; i += 64) {
450
+ md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
451
+ }
452
+
453
+ this._buff = this._buff.substring(i - 64);
454
+
455
+ return this;
456
+ };
457
+
458
+ /**
459
+ * Finishes the incremental computation, reseting the internal state and
460
+ * returning the result.
461
+ *
462
+ * @param {Boolean} raw True to get the raw string, false to get the hex string
463
+ *
464
+ * @return {String} The result
465
+ */
466
+ SparkMD5.prototype.end = function (raw) {
467
+ var buff = this._buff,
468
+ length = buff.length,
469
+ i,
470
+ tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
471
+ ret;
472
+
473
+ for (i = 0; i < length; i += 1) {
474
+ tail[i >> 2] |= buff.charCodeAt(i) << ((i % 4) << 3);
475
+ }
476
+
477
+ this._finish(tail, length);
478
+ ret = hex(this._hash);
479
+
480
+ if (raw) {
481
+ ret = hexToBinaryString(ret);
482
+ }
483
+
484
+ this.reset();
485
+
486
+ return ret;
487
+ };
488
+
489
+ /**
490
+ * Resets the internal state of the computation.
491
+ *
492
+ * @return {SparkMD5} The instance itself
493
+ */
494
+ SparkMD5.prototype.reset = function () {
495
+ this._buff = '';
496
+ this._length = 0;
497
+ this._hash = [1732584193, -271733879, -1732584194, 271733878];
498
+
499
+ return this;
500
+ };
501
+
502
+ /**
503
+ * Gets the internal state of the computation.
504
+ *
505
+ * @return {Object} The state
506
+ */
507
+ SparkMD5.prototype.getState = function () {
508
+ return {
509
+ buff: this._buff,
510
+ length: this._length,
511
+ hash: this._hash.slice()
512
+ };
513
+ };
514
+
515
+ /**
516
+ * Gets the internal state of the computation.
517
+ *
518
+ * @param {Object} state The state
519
+ *
520
+ * @return {SparkMD5} The instance itself
521
+ */
522
+ SparkMD5.prototype.setState = function (state) {
523
+ this._buff = state.buff;
524
+ this._length = state.length;
525
+ this._hash = state.hash;
526
+
527
+ return this;
528
+ };
529
+
530
+ /**
531
+ * Releases memory used by the incremental buffer and other additional
532
+ * resources. If you plan to use the instance again, use reset instead.
533
+ */
534
+ SparkMD5.prototype.destroy = function () {
535
+ delete this._hash;
536
+ delete this._buff;
537
+ delete this._length;
538
+ };
539
+
540
+ /**
541
+ * Finish the final calculation based on the tail.
542
+ *
543
+ * @param {Array} tail The tail (will be modified)
544
+ * @param {Number} length The length of the remaining buffer
545
+ */
546
+ SparkMD5.prototype._finish = function (tail, length) {
547
+ var i = length,
548
+ tmp,
549
+ lo,
550
+ hi;
551
+
552
+ tail[i >> 2] |= 0x80 << ((i % 4) << 3);
553
+ if (i > 55) {
554
+ md5cycle(this._hash, tail);
555
+ for (i = 0; i < 16; i += 1) {
556
+ tail[i] = 0;
557
+ }
558
+ }
559
+
560
+ // Do the final computation based on the tail and length
561
+ // Beware that the final length may not fit in 32 bits so we take care of that
562
+ tmp = this._length * 8;
563
+ tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
564
+ lo = parseInt(tmp[2], 16);
565
+ hi = parseInt(tmp[1], 16) || 0;
566
+
567
+ tail[14] = lo;
568
+ tail[15] = hi;
569
+ md5cycle(this._hash, tail);
570
+ };
571
+
572
+ /**
573
+ * Performs the md5 hash on a string.
574
+ * A conversion will be applied if utf8 string is detected.
575
+ *
576
+ * @param {String} str The string
577
+ * @param {Boolean} [raw] True to get the raw string, false to get the hex string
578
+ *
579
+ * @return {String} The result
580
+ */
581
+ SparkMD5.hash = function (str, raw) {
582
+ // Converts the string to utf8 bytes if necessary
583
+ // Then compute it using the binary function
584
+ return SparkMD5.hashBinary(toUtf8(str), raw);
585
+ };
586
+
587
+ /**
588
+ * Performs the md5 hash on a binary string.
589
+ *
590
+ * @param {String} content The binary string
591
+ * @param {Boolean} [raw] True to get the raw string, false to get the hex string
592
+ *
593
+ * @return {String} The result
594
+ */
595
+ SparkMD5.hashBinary = function (content, raw) {
596
+ var hash = md51(content),
597
+ ret = hex(hash);
598
+
599
+ return raw ? hexToBinaryString(ret) : ret;
600
+ };
601
+
602
+ // ---------------------------------------------------
603
+
604
+ /**
605
+ * SparkMD5 OOP implementation for array buffers.
606
+ *
607
+ * Use this class to perform an incremental md5 ONLY for array buffers.
608
+ */
609
+ SparkMD5.ArrayBuffer = function () {
610
+ // call reset to init the instance
611
+ this.reset();
612
+ };
613
+
614
+ /**
615
+ * Appends an array buffer.
616
+ *
617
+ * @param {ArrayBuffer} arr The array to be appended
618
+ *
619
+ * @return {SparkMD5.ArrayBuffer} The instance itself
620
+ */
621
+ SparkMD5.ArrayBuffer.prototype.append = function (arr) {
622
+ var buff = concatenateArrayBuffers(this._buff.buffer, arr),
623
+ length = buff.length,
624
+ i;
625
+
626
+ this._length += arr.byteLength;
627
+
628
+ for (i = 64; i <= length; i += 64) {
629
+ md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
630
+ }
631
+
632
+ this._buff = (i - 64) < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
633
+
634
+ return this;
635
+ };
636
+
637
+ /**
638
+ * Finishes the incremental computation, reseting the internal state and
639
+ * returning the result.
640
+ *
641
+ * @param {Boolean} raw True to get the raw string, false to get the hex string
642
+ *
643
+ * @return {String} The result
644
+ */
645
+ SparkMD5.ArrayBuffer.prototype.end = function (raw) {
646
+ var buff = this._buff,
647
+ length = buff.length,
648
+ tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
649
+ i,
650
+ ret;
651
+
652
+ for (i = 0; i < length; i += 1) {
653
+ tail[i >> 2] |= buff[i] << ((i % 4) << 3);
654
+ }
655
+
656
+ this._finish(tail, length);
657
+ ret = hex(this._hash);
658
+
659
+ if (raw) {
660
+ ret = hexToBinaryString(ret);
661
+ }
662
+
663
+ this.reset();
664
+
665
+ return ret;
666
+ };
667
+
668
+ /**
669
+ * Resets the internal state of the computation.
670
+ *
671
+ * @return {SparkMD5.ArrayBuffer} The instance itself
672
+ */
673
+ SparkMD5.ArrayBuffer.prototype.reset = function () {
674
+ this._buff = new Uint8Array(0);
675
+ this._length = 0;
676
+ this._hash = [1732584193, -271733879, -1732584194, 271733878];
677
+
678
+ return this;
679
+ };
680
+
681
+ /**
682
+ * Gets the internal state of the computation.
683
+ *
684
+ * @return {Object} The state
685
+ */
686
+ SparkMD5.ArrayBuffer.prototype.getState = function () {
687
+ var state = SparkMD5.prototype.getState.call(this);
688
+
689
+ // Convert buffer to a string
690
+ state.buff = arrayBuffer2Utf8Str(state.buff);
691
+
692
+ return state;
693
+ };
694
+
695
+ /**
696
+ * Gets the internal state of the computation.
697
+ *
698
+ * @param {Object} state The state
699
+ *
700
+ * @return {SparkMD5.ArrayBuffer} The instance itself
701
+ */
702
+ SparkMD5.ArrayBuffer.prototype.setState = function (state) {
703
+ // Convert string to buffer
704
+ state.buff = utf8Str2ArrayBuffer(state.buff, true);
705
+
706
+ return SparkMD5.prototype.setState.call(this, state);
707
+ };
708
+
709
+ SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
710
+
711
+ SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
712
+
713
+ /**
714
+ * Performs the md5 hash on an array buffer.
715
+ *
716
+ * @param {ArrayBuffer} arr The array buffer
717
+ * @param {Boolean} [raw] True to get the raw string, false to get the hex one
718
+ *
719
+ * @return {String} The result
720
+ */
721
+ SparkMD5.ArrayBuffer.hash = function (arr, raw) {
722
+ var hash = md51_array(new Uint8Array(arr)),
723
+ ret = hex(hash);
724
+
725
+ return raw ? hexToBinaryString(ret) : ret;
726
+ };
727
+
728
+ return SparkMD5;
729
+ }));
730
+ } (sparkMd5));
731
+
732
+ var sparkMd5Exports = sparkMd5.exports;
733
+ var SparkMD5 = /*@__PURE__*/getDefaultExportFromCjs(sparkMd5Exports);
734
+
735
+ function createFileChunk(file, size) {
736
+ const chunks = [];
737
+ let cur = 0;
738
+ const intSize = parseInt(size + "");
739
+ while (cur < file.size) {
740
+ chunks.push(file.slice(cur, cur + intSize));
741
+ cur += intSize;
742
+ }
743
+ return chunks;
744
+ }
745
+ function calculateFileHashSample(file) {
746
+ return new Promise((resolve) => {
747
+ const spark = new SparkMD5.ArrayBuffer();
748
+ const reader = new FileReader();
749
+ const size = file.size;
750
+ const offset = 2 * 1024 * 1024;
751
+ const chunks = [file.slice(0, offset)];
752
+ let cur = offset;
753
+ while (cur < size) {
754
+ if (cur + offset >= size) {
755
+ chunks.push(file.slice(cur, cur + offset));
756
+ } else {
757
+ const mid = cur + offset / 2;
758
+ const end = cur + offset;
759
+ chunks.push(file.slice(cur, cur + 2));
760
+ chunks.push(file.slice(mid, mid + 2));
761
+ chunks.push(file.slice(end - 2, end));
762
+ }
763
+ cur += offset;
764
+ }
765
+ reader.readAsArrayBuffer(new Blob(chunks));
766
+ reader.onload = (e) => {
767
+ spark.append(e.target?.result);
768
+ resolve(spark.end());
769
+ };
770
+ });
771
+ }
772
+
773
+ exports.calculateFileHashSample = calculateFileHashSample;
774
+ exports.createFileChunk = createFileChunk;