-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support big endian machines (trie file in LE) (#8)
- Loading branch information
1 parent
98df04c
commit fc9ea64
Showing
4 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const isBigEndian = (new Uint8Array(new Uint32Array([0x12345678]).buffer)[0] === 0x12); | ||
|
||
const swap = (b, n, m) => { | ||
let i = b[n]; | ||
b[n] = b[m]; | ||
b[m] = i; | ||
}; | ||
|
||
const swap32 = array => { | ||
const len = array.length; | ||
for (let i = 0; i < len; i += 4) { | ||
swap(array, i, i + 3); | ||
swap(array, i + 1, i + 2); | ||
} | ||
}; | ||
|
||
const swap32LE = array => { | ||
if (isBigEndian) { | ||
swap32(array); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
swap32LE: swap32LE | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters