When you read a chunk of bytes and you need to convert them to a number, node.js has functions like buffer.readInt32BE()
and buffer.readInt32LE()
.
If I only know that the first 4 bytes of a file is an integer, what function should I use if I don't know the endianness of the system? Big endian or little endian?
Doing a fast googling (stackoverflow), in C we can test the endianness doing:
if ( htonl(47) == 47 ) {
// Big endian
} else {
// Little endian.
}
How can we test the endianness in node.js to properly use readInt32BE and readInt32Le?