binary-buffer-parser
A simple binary buffer parser.
Download
binary-buffer-parser is installable via:
-
GitHub
git clone https://github.com/Pupix/binary-buffer-parser.git
-
npm:
npm install binary-buffer-parser
Quick example
var BinaryParser = require('binary-buffer-parser'),
buffer = new Buffer('Hello world!')
parser = new BinaryParser(buffer);
console.log(parser.int8()); // 72
console.log(parser.uint32()); // 1869376613
console.log(parser.stringView().join('')) // Hello World!
Methods
####Helper Methods
####Generic Methods
int8 / byte
uint8 / ubyte
int16 / short
uint16 / ushort
int32 / int
uint32 / uint
float
double / long
string
string0
####Bitfield Methods
####View Methods
Documentation ## Helper Methods ### endianess(endian)
Sets the endian format of the parser.
Parameters
-
endian {string} The new endian format. Can be either
little
/LE
for little endian orbig
/BE
for big endian.
Returns the length of the buffer.
### seek(offset)Sets the offset of the reading cursor at the passed position, starting from the beginning of the buffer.
- offset {number} The new value of the new offset position.
Advances the reading cursor by the passed offset from its current position.
- offset {number} The number of bytes to skip over.
Returns the position of the reading cursor inside the buffer.
## Generic Methods ### int8(length) / byte(length)Reads a signed 8 bit integer from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of int8 to read consecutively
Reads a unsigned 8 bit integer from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of uint8 to read consecutively
Reads a signed 16 bit integer from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of int16 to read consecutively
Reads a unsigned 16 bit integer from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of uint16 to read consecutively
Reads a signed 32 bit integer from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of int32 to read consecutively
Reads a unsigned 32 bit integer from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of uint32 to read consecutively
Reads a 32 bit float from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of floats to read consecutively
Reads a unsigned 64 bit double from the buffer. If length
is passed, the same function
will be ran multiple times and return the result as an array.
Parameters
- [length] {number} The number of doubles to read consecutively
Reads an ASCII string from the buffer.
Parameters
- length {number} The length of the string.
Reads a null terminated ASCII string from the buffer.
## Bitfield methods ### bit8()Reads an unsigned 8 bit integer from the buffer and returns an array with true
/false
based on the values of each bit.
Reads an unsigned 16 bit integer from the buffer and returns an array with true
/false
based on the values of each bit.
Reads an unsigned 32 bit integer from the buffer and returns an array with true
/false
based on the values of each bit.
Returns the buffer in ASCII encoding inside an array, divided by character.
### hexView()Returns the buffer in hexadecimal encoding inside an array, divided by byte.
### ansiView()Returns the buffer in ANSI encoding inside an array, divided by character.