@@ -6,11 +6,11 @@ library. It is currently being proposed as a Pull-Request in that project.
66Until the * encoding* feature is merged in baseline of original project,
77this branch is published under the name: ** binary-parser-encoder** in [ npm] ( https://npmjs.org/ ) .
88
9+ [ ![ build] ( https://github.com/Ericbla/binary-parser/workflows/build/badge.svg )] ( https://github.com/Ericbla/binary-parser/actions?query=workflow%3Abuild )
10+ [ ![ npm] ( https://img.shields.io/npm/v/binary-parser-encoder )] ( https://www.npmjs.com/package/binary-parser-encoder )
911
10- [ ![ Circle CI] ( https://circleci.com/gh/Ericbla/binary-parser.svg?style=svg )] ( https://circleci.com/gh/Ericbla/binary-parser )
11-
12- Binary-parser is a binary parser/encoder builder for [ node] ( http://nodejs.org ) that
13- enables you to write efficient parsers/encoders in a simple and declarative manner.
12+ Binary-parser is a parser/encoder builder for JavaScript that enables you to write
13+ efficient binary parsers/encoders in a simple and declarative manner.
1414
1515It supports all common data types required to analyze a structured binary
1616data. Binary-parser dynamically generates and compiles the parser and encoder code
@@ -35,12 +35,14 @@ Binary-parser was inspired by [BinData](https://github.com/dmendel/bindata)
3535and [ binary] ( https://github.com/substack/node-binary ) .
3636
3737## Quick Start
38+
38391 . Create an empty Parser object with ` new Parser() ` or ` Parser.start() ` .
39402 . Chain methods to build your desired parser and/or encoder. (See
4041 [ API] ( https://github.com/keichi/binary-parser#api ) for detailed document of
4142 each method)
42- 3 . Call ` Parser.prototype.parse ` with an ` Buffer ` object passed as an argument.
43- 4 . Parsed result will be returned as an object.
43+ 3 . Call ` Parser.prototype.parse ` with a ` Buffer ` /` Uint8Array ` object passed as
44+ an argument.
45+ 4 . The parsed result will be returned as an object.
44465 . Or call ` Parser.prototype.encode ` with an object passed as argument.
45476 . Encoded result will be returned as a ` Buffer ` object.
4648
@@ -97,15 +99,15 @@ console.log(ipHeader.encode(anIpHeader).toString("hex"));
9799## API
98100
99101### new Parser([ options] )
100- Constructs a Parser object. Returned object represents a parser which parses
101- nothing. ` options ` is an optional object to pass options to this declarative
102+ Create an empty parser object that parses nothing.
103+ ` options ` is an optional object to pass options to this declarative
102104parser.
103105 - ` smartBufferSize ` The chunk size of the encoding (smart)buffer (when encoding is used) (default is 256 bytes).
104106
105107### parse(buffer)
106- Parse a ` Buffer ` object ` buffer ` with this parser and return the resulting
107- object. When ` parse(buffer) ` is called for the first time, the associated
108- parser code is compiled on-the-fly and internally cached.
108+ Parse a ` Buffer ` / ` Uint8Array ` object ` buffer ` with this parser and return the
109+ resulting object. When ` parse(buffer) ` is called for the first time, the
110+ associated parser code is compiled on-the-fly and internally cached.
109111
110112### encode(obj)
111113Encode an ` Object ` object ` obj ` with this parser and return the resulting
@@ -163,10 +165,9 @@ characters and start with an alphabet. `options` is an object which can have
163165the following keys:
164166
165167- ` encoding ` - (Optional, defaults to ` utf8 ` ) Specify which encoding to use.
166- Supported encodings include ` "utf8" ` , ` "ascii" ` and ` "hex" ` . See
167- [ ` Buffer.toString ` ] ( http://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end )
168- for more info.
169- - ` length ` - (Optional) (Bytes)Length of the string. Can be a number, string or a
168+ Supported encodings include ` "hex" ` and all encodings supported by
169+ [ ` TextDecoder ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding ) .
170+ - ` length ` - (Optional) Length of the string. Can be a number, string or a
170171 function. Use number for statically sized arrays, string to reference
171172 another variable and function to do some calculation.
172173 Note: When encoding the string is padded with a ` padd ` charecter to fit the length requirement.
@@ -188,9 +189,10 @@ the following keys:
188189 or utf8 < 0x80 are alowed. Note: The default padd character is * space* (or * null* when ` stripNull ` is used).
189190
190191### buffer(name[ , options] )
191- Parse bytes as a buffer. ` name ` should consist only of alpha numeric
192- characters and start with an alphabet. ` options ` is an object which can have
193- the following keys:
192+ Parse bytes as a buffer. Its type will be the same as the input to
193+ ` parse(buffer) ` . ` name ` should consist only of alpha numeric characters and
194+ start with an alphabet. ` options ` is an object which can have the following
195+ keys:
194196
195197- ` clone ` - (Optional, defaults to ` false ` ) By default,
196198 ` buffer(name [,options]) ` returns a new buffer which references the same
@@ -202,9 +204,9 @@ the following keys:
202204 sized buffers, string to reference another variable and function to do some
203205 calculation.
204206- ` readUntil ` - (either ` length ` or ` readUntil ` is required) If ` "eof" ` , then
205- this parser will read till it reaches end of the ` Buffer ` object. (Note: has no
206- effect on encoding.)
207- If it is a function, this parser will read the buffer is read until the
207+ this parser will read till it reaches the end of the ` Buffer ` / ` Uint8Array `
208+ object. (Note: has no effect on encoding.)
209+ If it is a function, this parser will read the buffer until the
208210 function returns true.
209211
210212### array(name, options)
@@ -221,8 +223,9 @@ keys:
221223 required) Length of the array expressed in bytes. Can be a number, string or
222224 a function. Use number for statically sized arrays.
223225- ` readUntil ` - (either ` length ` , ` lengthInBytes ` , or ` readUntil ` is required)
224- If ` "eof" ` , then this parser reads until the end of ` Buffer ` object. If
225- function it reads until the function returns true. ** <u >Note</u >** : When encoding,
226+ If ` "eof" ` , then this parser reads until the end of the ` Buffer ` /` Uint8Array `
227+ object. If function it reads until the function returns true.
228+ ** <u >Note</u >** : When encoding,
226229 the ` buffer ` second parameter of ` readUntil ` function is the buffer already encoded
227230 before this array. So no * read-ahead* is possible.
228231- ` encodeUntil ` - a function (item, object), only used when encoding, that replaces
@@ -364,8 +367,8 @@ var parser = new Parser()
364367
365368### seek(relOffset)
366369Move the buffer offset for ` relOffset ` bytes from the current position. Use a
367- negative ` relOffset ` value to rewind the offset. Previously named ` skip(length) ` .
368- (Note: when encoding, the skipped bytes will be filled with zeros)
370+ negative ` relOffset ` value to rewind the offset. This method was previously
371+ named ` skip(length) ` . (Note: when encoding, the skipped bytes will be filled with zeros)
369372
370373### endianess(endianess)
371374Define what endianess to use in this parser. ` endianess ` can be either
@@ -382,7 +385,7 @@ var parser = new Parser()
382385 .int32 (" c" );
383386```
384387
385- ### setEncoderOptions (opts)
388+ ### encoderSetOptions (opts)
386389Set specific options for encoding.
387390Current supported ` opts ` object may contain:
388391 - bitEndianess: true|false (default false) When true, tell the encoder to respect endianess BITs order, so that
@@ -391,7 +394,7 @@ Current supported `opts` object may contain:
391394``` javascript
392395var parser = new Parser ()
393396 .endianess (" little" )
394- .setEncoderOpts ({bitEndianess: true }) // Use BITs endianess for bits fields
397+ .encoderSetOptions ({bitEndianess: true }) // Use BITs endianess for bits fields
395398 .bit4 (" a" )
396399 .bit4 (" b" )
397400 .uint16 (" c" );
0 commit comments