Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 89 lines (62 sloc) 2.033 kb
11b5c60 @substack rebranded as binary
authored
1 Binary
2 ======
9ebc04e @substack readme woo
authored
3
4 Unpack multibyte binary values from buffers and streams.
5 You can specify the endianness and signedness of the fields to be unpacked too.
6
1e33146 @substack buf.js example
authored
7 This module is a cleaner, faster, and more complete version of
8 [bufferlist](https://github.com/substack/node-bufferlist)'s binary module that
9 runs on pre-allocated buffers instead of a linked list.
10
11 Examples
12 ========
13
14 buf.js
15 ------
16 var buf = new Buffer([ 97, 98, 99, 100, 101, 102, 0 ]);
17
18 var Binary = require('binary');
19 Binary(buf)
20 .word16ls('ab')
21 .word32bu('cf')
22 .word8('x')
23 .tap(function (vars) {
24 console.dir(vars);
25 })
26 ;
27 -
28 $ node buf.js
29 { ab: 25185, cf: 1667523942, x: 0 }
30
8464aae @substack readme updates for the methods
authored
31 Methods
32 =======
33
34 Binary(buf)
35 -----------
36
37 Start a new chain parser for a `Buffer`.
38
39 Binary(emitter)
40 ---------------
41 Binary(emitter, eventName='data')
42 ---------------------------------
43
44 Start a new chain parser for an `EventEmitter` for an event name `eventName`,
45 which defaults to `'data'`.
46
47 word{8,16,32,64}{l,b}{e,u,s}(name)
48 ----------------------------------
49
50 Parse bytes in the buffer or stream given:
51
52 # number of bits
53 # endianness ( l : little, b : big ),
54 # signedness ( u and e : unsigned, s : signed )
55
56 These functions won't start parsing until all previous parser functions have run
57 and the data is available.
58
59 The result of the parse goes into the variable stash at `name`.
60
61 tap(cb)
62 -------
63
64 The callback `cb` is provided with the variable stash from all the previous
65 actions once they've all finished.
66
9ebc04e @substack readme woo
authored
67 Installation
68 ============
69
70 To install with [npm](http://github.com/isaacs/npm):
71
11b5c60 @substack rebranded as binary
authored
72 npm install binary
9ebc04e @substack readme woo
authored
73
74 To run the tests with [expresso](http://github.com/visionmedia/expresso):
75
76 expresso
1e33146 @substack buf.js example
authored
77
78 Notes
79 =====
80
81 The word64 functions will only return approximations since javascript uses ieee
82 floating point for all number types. Mind the loss of precision.
83
84 Todo
85 ====
86
87 * Actually verify that this approach is faster than bufferlist/binary.
88 * Add all the nifty nested parser functions without sacrificing performance.
Something went wrong with that request. Please try again.