You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79-79Lines changed: 79 additions & 79 deletions
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,7 @@ With no prefix, it parses as a signed number, with `u` prefixed as an unsigned n
91
91
92
92
```javascript
93
93
var parser =newParser()
94
-
// Signed 32-bit integer (little endian)
94
+
// Signed 32-bit integer (little endian)
95
95
.int32le('a')
96
96
// Unsigned 8-bit integer
97
97
.uint8('b')
@@ -126,7 +126,7 @@ with an alphabet. `options` is an object; following options are available:
126
126
Use number for statically sized arrays, string to reference another variable and
127
127
function to do some calculation.
128
128
-`zeroTerminated` - (Optional, defaults to `false`) If true, then this parser reads until it reaches zero.
129
-
-`greedy - (Optional, defaults to `false`) If true, then this parser reads until it reaches the end of the buffer. Will consume zero-bytes.
129
+
-`greedy` - (Optional, defaults to `false`) If true, then this parser reads until it reaches the end of the buffer. Will consume zero-bytes.
130
130
-`stripNull` - (Optional, must be used with `length`) If true, then strip null characters from end of the string
131
131
132
132
### buffer(name [,options])
@@ -149,63 +149,63 @@ Parse bytes as an array. `options` is an object; following options are available
149
149
-`type` - (Required) Type of the array element. Can be a string or an user defined Parser object.
150
150
If it's a string, you have to choose from [u]int{8, 16, 32}{le, be}.
151
151
-`length` - (either `length`, `lengthInBytes`, or `readUntil` is required) Length of the array. Can be a number, string or a function.
152
-
Use number for statically sized arrays.
152
+
Use number for statically sized arrays.
153
153
-`lengthInBytes` - (either `length`, `lengthInBytes`, or `readUntil` is required) Length of the array expressed in bytes. Can be a number, string or a function.
154
-
Use number for statically sized arrays.
154
+
Use number for statically sized arrays.
155
155
-`readUntil` - (either `length`, `lengthInBytes`, or `readUntil` is required) If `'eof'`, then this parser
156
-
reads until the end of `Buffer` object. If function it reads until the function returns true.
156
+
reads until the end of `Buffer` object. If function it reads until the function returns true.
157
157
158
158
```javascript
159
159
var parser =newParser()
160
-
// Statically sized array
161
-
.array('data', {
162
-
type:'int32',
163
-
length:8
164
-
})
165
-
166
-
// Dynamically sized array (reference another variable)
167
-
.uint8('dataLength')
168
-
.array('data2', {
169
-
type:'int32',
170
-
length:'dataLength'
171
-
})
172
-
173
-
// Dynamically sized array (with some calculation)
174
-
.array('data3', {
175
-
type:'int32',
176
-
length:function() { returnthis.dataLength-1; } // other fields are available through this
177
-
});
178
-
179
-
// Statically sized array
180
-
.array('data4', {
181
-
type:'int32',
182
-
lengthInBytes:16
183
-
})
184
-
185
-
// Dynamically sized array (reference another variable)
186
-
.uint8('dataLengthInBytes')
187
-
.array('data5', {
188
-
type:'int32',
189
-
lengthInBytes:'dataLengthInBytes'
190
-
})
191
-
192
-
// Dynamically sized array (with some calculation)
193
-
.array('data6', {
194
-
type:'int32',
195
-
lengthInBytes:function() { returnthis.dataLengthInBytes-4; } // other fields are available through this
196
-
})
197
-
198
-
// Dynamically sized array (with stop-check on parsed item)
199
-
.array('data7', {
200
-
type:'int32',
201
-
readUntil:function(item, buffer) { return item ===42 } // stop when specific item is parsed. buffer can be used to perform a read-ahead.
202
-
});
203
-
204
-
// Use user defined parser object
205
-
.array('data8', {
206
-
type: userDefinedParser,
207
-
length:'dataLength'
208
-
});
160
+
// Statically sized array
161
+
.array('data', {
162
+
type:'int32',
163
+
length:8
164
+
})
165
+
166
+
// Dynamically sized array (references another variable)
167
+
.uint8('dataLength')
168
+
.array('data2', {
169
+
type:'int32',
170
+
length:'dataLength'
171
+
})
172
+
173
+
// Dynamically sized array (with some calculation)
174
+
.array('data3', {
175
+
type:'int32',
176
+
length:function() { returnthis.dataLength-1; } // other fields are available through this
177
+
});
178
+
179
+
// Statically sized array
180
+
.array('data4', {
181
+
type:'int32',
182
+
lengthInBytes:16
183
+
})
184
+
185
+
// Dynamically sized array (references another variable)
186
+
.uint8('dataLengthInBytes')
187
+
.array('data5', {
188
+
type:'int32',
189
+
lengthInBytes:'dataLengthInBytes'
190
+
})
191
+
192
+
// Dynamically sized array (with some calculation)
193
+
.array('data6', {
194
+
type:'int32',
195
+
lengthInBytes:function() { returnthis.dataLengthInBytes-4; } // other fields are available through this
196
+
})
197
+
198
+
// Dynamically sized array (with stop-check on parsed item)
199
+
.array('data7', {
200
+
type:'int32',
201
+
readUntil:function(item, buffer) { return item ===42 } // stop when specific item is parsed. buffer can be used to perform a read-ahead.
202
+
});
203
+
204
+
// Use user defined parser object
205
+
.array('data8', {
206
+
type: userDefinedParser,
207
+
length:'dataLength'
208
+
});
209
209
```
210
210
211
211
### choice(name [,options])
@@ -214,9 +214,9 @@ Combining `choice` with `array` is useful for parsing a typical
0 commit comments