Skip to content

Commit 1a5daad

Browse files
committed
docs: update readme to reflect the new feature
1 parent 4c5d452 commit 1a5daad

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -438,21 +438,27 @@ const buffer = Buffer.from([2, /* left */ 1, 1, 0, /* right */ 0]);
438438
parser.parse(buffer);
439439
```
440440

441-
### wrapped(name[, options])
442-
Read data then wrap it by transforming it by a function for further parsing.
443-
It works similarly to a buffer where it reads a block of data. But instead of returning the buffer it
444-
will pass it on to a parser for further processing.
445-
- `wrapper` - (Required) A function taking a buffer and returning a buffer (`(x: Buffer | Uint8Array ) => Buffer | Uint8Array`)
446-
transforming the buffer into a buffer expected by `type`.
447-
- `type` - (Required) A `Parser` object to parse the result of wrapper.
441+
### wrapped([name,] options)
442+
Read data, then wrap it by transforming it by a function for further parsing.
443+
It works similarly to a buffer where it reads a block of data. But instead of
444+
returning the buffer it will pass the buffer on to a parser for further processing.
445+
446+
The result will be stored in the key `name`. If `name` is an empty string or
447+
`null`, or if it is omitted, the parsed result is directly embedded into the
448+
current object.
449+
450+
- `wrapper` - (Required) A function taking a buffer and returning a buffer
451+
(`(x: Buffer | Uint8Array ) => Buffer | Uint8Array`) transforming the buffer
452+
into a buffer expected by `type`.
453+
- `type` - (Required) A `Parser` object to parse the buffer returned by `wrapper`.
448454
- `length ` - (either `length` or `readUntil` is required) Length of the
449-
buffer. Can be a number, string or a function. Use number for statically
450-
sized buffers, string to reference another variable and function to do some
455+
buffer. Can be a number, string or a function. Use a number for statically
456+
sized buffers, a string to reference another variable and a function to do some
451457
calculation.
452458
- `readUntil` - (either `length` or `readUntil` is required) If `"eof"`, then
453459
this parser will read till it reaches the end of the `Buffer`/`Uint8Array`
454460
object. If it is a function, this parser will read the buffer until the
455-
function returns true.
461+
function returns `true`.
456462

457463
```javascript
458464
const zlib = require("zlib");
@@ -474,9 +480,10 @@ const mainParser = Parser.start()
474480
// E.g. decompress data and return it for further parsing
475481
return zlib.inflateRawSync(buffer);
476482
},
477-
// The parser to run the dec
483+
// The parser to run on the decompressed data
478484
type: textParser,
479485
});
486+
480487
mainParser.parse(buffer);
481488
```
482489

0 commit comments

Comments
 (0)