The Node.js StringDecoder is used to decode buffer into string. It is similar to buffer.toString() but provides extra support to UTF.
You need to use require('string_decoder') to use StringDecoder module.
Node.js StringDecoder Methods
StringDecoder class has two methods only.
Method | Description |
---|---|
decoder.write(buffer) | It is used to return the decoded string. |
decoder.end() | It is used to return trailing bytes, if any left in the buffer. |
Node.js StringDecoder Example
Let's see a simple example of Node.js StringDecoder.
File: stringdecoder_example1.js

No comments:
Post a Comment