@@ -532,17 +532,18 @@ console.log(b.toString());
532
532
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
533
533
```
534
534
535
- ### buf.indexOf(value[ , byteOffset] )
535
+ ### buf.indexOf(value[ , byteOffset] [ , encoding ] )
536
536
537
537
* ` value ` String, Buffer or Number
538
538
* ` byteOffset ` Number, Optional, Default: 0
539
+ * ` encoding ` String, Optional, Default: ` utf8 `
539
540
* Return: Number
540
541
541
542
Operates similar to [ ` Array#indexOf() ` ] [ ] in that it returns either the
542
543
starting index position of ` value ` in Buffer or ` -1 ` if the Buffer does not
543
- contain ` value ` . The ` value ` can be a String, Buffer or Number. Strings are
544
- interpreted as UTF8. Buffers will use the entire Buffer (to compare a partial
545
- Buffer use [ ` Buffer#slice() ` ] [ ] ). Numbers can range from 0 to 255.
544
+ contain ` value ` . The ` value ` can be a String, Buffer or Number. Strings are by
545
+ default interpreted as UTF8. Buffers will use the entire Buffer (to compare a
546
+ partial Buffer use [ ` Buffer#slice() ` ] [ ] ). Numbers can range from 0 to 255.
546
547
547
548
``` js
548
549
const buf = new Buffer (' this is a buffer' );
@@ -559,6 +560,13 @@ buf.indexOf(new Buffer('a buffer example'));
559
560
// returns -1
560
561
buf .indexOf (new Buffer (' a buffer example' ).slice (0 ,8 ));
561
562
// returns 8
563
+
564
+ const utf16Buffer = new Buffer (' \u039a\u0391\u03a3\u03a3\u0395 ' , ' ucs2' );
565
+
566
+ utf16Buffer .indexOf (' \u03a3 ' , 0 , ' ucs2' );
567
+ // returns 4
568
+ utf16Buffer .indexOf (' \u03a3 ' , - 4 , ' ucs2' );
569
+ // returns 6
562
570
```
563
571
564
572
### buf.includes(value[ , byteOffset] [ , encoding ] )
0 commit comments