bit-reader.js 1013 B

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