Unpack multibyte binary values from buffers and streams. (Maintenance fork of substack's `binary`)
npm install binary-pmb
binary-pmb
==========
Unpack multibyte binary values from buffers and streams. (Maintenance fork of
substack's binary)
You can specify the endianness and signedness of the fields to be unpacked too.
This module is a cleaner and more complete version of
bufferlist's binary module that
runs on pre-allocated buffers instead of a linked list.

Installation
============
``bash`
npm install binary
Examples
========
See the docs/examples/ directory.
API
===
`javascript`
var binary = require('binary-pmb')
* var b = binary()
* binary.parse(buf)
* b.vars
* b.word{8,16,24,32,64}{l,b}{e,u,s}(key)
* b.buffer(key, size)
* b.str(key, size[, encoding])
* b.utf8(key, size)
* b.skip(dist)
* b.scan(key, buffer)
* b.tap(cb)
* b.into(key, cb)
* b.loop(cb)
* b.flush()
Return a new writable stream b that has the chainable methods documented below
for buffering binary input.
Parse a static buffer in one pass. Returns a chainable interface with the
methods below plus a vars field to get at the variable stash as the
last item in a chain.
In parse mode, methods will set their keys to null if the buffer isn't bigbuffer()
enough except and scan() which read up up to the end of the buffer
and stop.
See binary.parse.
Parse bytes in the buffer or stream given:
* number of bits
* endianness ( l : little, b : big ),
* signedness ( u and e : unsigned, s : signed )
These functions won't start parsing until all previous parser functions have run
and the data is available.
The result of the parse goes into the variable stash at key.key
If has dots (.s), it refers to a nested address. If parent containerdst.addr
values don't exist they will be created automatically, so for instance you can
assign into and dst.port and the dst key in the variable stash{ addr : x, port : y }
will be afterwards.
Take size bytes directly off the buffer stream, putting the resulting bufferkey
slice in the variable stash at .
__vars lookup:__ If size is a string, use the value at vars[size].
The key follows the same dotted address rules as the word functions.
Same as .buffer but decode the data as a string.encoding
Default is latin1.
Same as .buffer but decode the data as a UTF-8 string.
Jump dist bytes ahead..buffer
The "vars lookup" feature from applies to dist.
Search for buffer in the stream and store all the intervening data in thekey
stash at at , excluding the search buffer. If buffer passed as a string,
it will be converted into a Buffer internally.
For example, to read in a line you can just do:
`javascript`
var b = binary()
.scan('line', new Buffer('\r\n'))
.tap(function (vars) {
console.log(vars.line)
})
;
stream.pipe(b);
The callback cb is provided with the variable stash from all the previous
actions once they've all finished.
You can nest additional actions onto this inside the callback.
Like .tap(), except all nested actions will assign into a key in the vars
stash.
Loop, each time calling cb(end, vars) for function end and the variablethis
stash with set to a new chain for nested parsing. The loop terminatesend` is called.
once
Clear the variable stash entirely.
Known issues
------------
* The word64 functions will only return approximations since javascript
uses IEEE floating point for all number types. Mind the loss of precision.
License
-------
MIT