Socket
Book a DemoInstallSign in
Socket

convert-endianness

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convert-endianness

Easily convert Little/Big endian typed arrays to the host endianness

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

convert-endianness

Easily convert Little/Big endian typed arrays to the host endianness or back.

npm install convert-endianness

The endianness of typed arrays is host specific. This might be an issue if you want to send them over the wire or persist them to disk. This module makes it easily to guarantee an endianness.

Usage

const endianness = require('convert-endianness')

const arr = new Int32Array(2)

arr[0] = 10
arr[1] = 1000000

console.log('as host:', arr)

// ensures the endianness of arr is big endian
endianness.hostToBE(arr)

// if your machine is LE (prob is) then array has changed
console.log('as BE:', arr)

// convert it back to the host endianness
endianness.BEToHost(arr)

console.log('as host again:', arr)

API

endianness.hostToLE(typedArray)

Converts the endianness of the typed array to little endian. If your machine is little endian, this is a noop.

endianness.LEToHost(typedArray)

Converts the endianness of the typed array from little endian to your host endian. If your machine is little endian, this is a noop.

endianness.hostToBE(typedArray)

Converts the endianness of the typed array to big endian. If your machine is big endian, this is a noop.

endianness.BEToHost(typedArray)

Converts the endianness of the typed array from big endian to your host endian. If your machine is big endian, this is a noop.

endianness.LE

True if your machine is little endian.

endianness.BE

True if your machine is big endian.

License

MIT

FAQs

Package last updated on 21 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts