* Converts a string into a Uint8Array for use with compression/decompression methods * @param str The string to encode * @param latin1 Whether or not to interpret the data as Latin-1. This should * not need to be true unless decoding a binary string. * @returns The string encoded i
(str, latin1)
| 775 | * @returns The string encoded in UTF-8/Latin-1 binary |
| 776 | */ |
| 777 | function strToU8(str, latin1) { |
| 778 | var i; |
| 779 | if (te) return te.encode(str); |
| 780 | var l = str.length; |
| 781 | var ar = new u8(str.length + (str.length >> 1)); |
| 782 | var ai = 0; |
| 783 | var w = function (v) { |
| 784 | ar[ai++] = v; |
| 785 | }; |
| 786 | for (var i = 0; i < l; ++i) { |
| 787 | if (ai + 5 > ar.length) { |
| 788 | var n = new u8(ai + 8 + ((l - i) << 1)); |
| 789 | n.set(ar); |
| 790 | ar = n; |
| 791 | } |
| 792 | var c = str.charCodeAt(i); |
| 793 | if (c < 128 || latin1) w(c); |
| 794 | else if (c < 2048) (w(192 | (c >> 6)), w(128 | (c & 63))); |
| 795 | else if (c > 55295 && c < 57344) |
| 796 | ((c = (65536 + (c & (1023 << 10))) | (str.charCodeAt(++i) & 1023)), |
| 797 | w(240 | (c >> 18)), |
| 798 | w(128 | ((c >> 12) & 63)), |
| 799 | w(128 | ((c >> 6) & 63)), |
| 800 | w(128 | (c & 63))); |
| 801 | else (w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63))); |
| 802 | } |
| 803 | return slc(ar, 0, ai); |
| 804 | } |
| 805 | |
| 806 | class Compressor { |
| 807 | constructor() { |