bit-reader.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.decodeBits = void 0;
  4. const Base64 = ")!@#$%^&*(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
  5. /**
  6. * @_ignore
  7. */
  8. function decodeBits(width, data) {
  9. const maxValue = (1 << width) - 1;
  10. const result = [];
  11. let accum = 0, bits = 0, flood = 0;
  12. for (let i = 0; i < data.length; i++) {
  13. // Accumulate 6 bits of data
  14. accum = ((accum << 6) | Base64.indexOf(data[i]));
  15. bits += 6;
  16. // While we have enough for a word...
  17. while (bits >= width) {
  18. // ...read the word
  19. const value = (accum >> (bits - width));
  20. accum &= (1 << (bits - width)) - 1;
  21. bits -= width;
  22. // A value of 0 indicates we exceeded maxValue, it
  23. // floods over into the next value
  24. if (value === 0) {
  25. flood += maxValue;
  26. }
  27. else {
  28. result.push(value + flood);
  29. flood = 0;
  30. }
  31. }
  32. }
  33. return result;
  34. }
  35. exports.decodeBits = decodeBits;
  36. //# sourceMappingURL=bit-reader.js.map