You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

26 lines
440 B

  1. const isBigEndian = (new Uint8Array(new Uint32Array([0x12345678]).buffer)[0] === 0x12);
  2. const swap = (b, n, m) => {
  3. let i = b[n];
  4. b[n] = b[m];
  5. b[m] = i;
  6. };
  7. const swap32 = array => {
  8. const len = array.length;
  9. for (let i = 0; i < len; i += 4) {
  10. swap(array, i, i + 3);
  11. swap(array, i + 1, i + 2);
  12. }
  13. };
  14. const swap32LE = array => {
  15. if (isBigEndian) {
  16. swap32(array);
  17. }
  18. };
  19. module.exports = {
  20. swap32LE: swap32LE
  21. };