Skip to content

Commit b9e940a

Browse files
committed
add examples for readString
1 parent 0c68636 commit b9e940a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/decoder.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ export class Decoder {
389389
* @param opts.zeroed - Read until a null terminator (`0x00`) is reached.
390390
* @param opts.length - Bytes to read.
391391
* @param opts.encoding - Defaults to `utf8`.
392+
* @example Zeroed
393+
* ```ts
394+
* const decoder = new Decoder(Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00]))
395+
* decoder.readString({ zeroed: true }) // "hello"
396+
* ```
397+
* @example Length
398+
* ```ts
399+
* const decoder = new Decoder(Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]))
400+
* decoder.readString({ length: 5 }) // "hello"
401+
* ```
392402
*/
393403
readString(opts: StringOptions): string {
394404
let strBuffer: Buffer | null = null

0 commit comments

Comments
 (0)