Skip to content

Commit b04a0aa

Browse files
committed
Adds examples for String Decoder related utility functions;
Signed-off-by: Ashwin Hegde <ashwin.hegde3@gmail.com>
1 parent 4a9d8b3 commit b04a0aa

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/***
2+
* The goal of this file is to know about the string decoder functions;
3+
* A simple interface to buffer.toString() but provides additional support for utf8.
4+
*
5+
* How to run this example:
6+
* 1. node stringDecoder.js
7+
* 2. See the message get displayed on prompt.
8+
*/
9+
10+
var cent = new Buffer([0x40]);
11+
console.log(cent.toString());
12+
13+
var StringDecoder = require('string_decoder').StringDecoder;
14+
var decoder = new StringDecoder('utf8');
15+
16+
/***
17+
* decoder.write returns a decoded string.
18+
*/
19+
cent = new Buffer([0xC2, 0xA2]);
20+
console.log(decoder.write(cent));
21+
22+
var euro = new Buffer([0xE2, 0x82, 0xAC]);
23+
console.log(decoder.write(euro));
24+

0 commit comments

Comments
 (0)