@vunk/form 1.1.12 → 1.1.13

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