Util.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.polyUint32Array = exports.polyUint16Array = exports.decode = void 0;
  4. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  5. // Use a lookup table to find the index.
  6. var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
  7. for (var i = 0; i < chars.length; i++) {
  8. lookup[chars.charCodeAt(i)] = i;
  9. }
  10. var decode = function (base64) {
  11. var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
  12. if (base64[base64.length - 1] === '=') {
  13. bufferLength--;
  14. if (base64[base64.length - 2] === '=') {
  15. bufferLength--;
  16. }
  17. }
  18. var buffer = typeof ArrayBuffer !== 'undefined' &&
  19. typeof Uint8Array !== 'undefined' &&
  20. typeof Uint8Array.prototype.slice !== 'undefined'
  21. ? new ArrayBuffer(bufferLength)
  22. : new Array(bufferLength);
  23. var bytes = Array.isArray(buffer) ? buffer : new Uint8Array(buffer);
  24. for (i = 0; i < len; i += 4) {
  25. encoded1 = lookup[base64.charCodeAt(i)];
  26. encoded2 = lookup[base64.charCodeAt(i + 1)];
  27. encoded3 = lookup[base64.charCodeAt(i + 2)];
  28. encoded4 = lookup[base64.charCodeAt(i + 3)];
  29. bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
  30. bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  31. bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
  32. }
  33. return buffer;
  34. };
  35. exports.decode = decode;
  36. var polyUint16Array = function (buffer) {
  37. var length = buffer.length;
  38. var bytes = [];
  39. for (var i = 0; i < length; i += 2) {
  40. bytes.push((buffer[i + 1] << 8) | buffer[i]);
  41. }
  42. return bytes;
  43. };
  44. exports.polyUint16Array = polyUint16Array;
  45. var polyUint32Array = function (buffer) {
  46. var length = buffer.length;
  47. var bytes = [];
  48. for (var i = 0; i < length; i += 4) {
  49. bytes.push((buffer[i + 3] << 24) | (buffer[i + 2] << 16) | (buffer[i + 1] << 8) | buffer[i]);
  50. }
  51. return bytes;
  52. };
  53. exports.polyUint32Array = polyUint32Array;
  54. //# sourceMappingURL=Util.js.map