Home >Web Front-end >JS Tutorial >Instructions for using the buffer.Buffer.isEncoding method in node.js_node.js

Instructions for using the buffer.Buffer.isEncoding method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:27:241607browse

Method description:

Check whether it is a valid encoding parameter and return true or false.

Grammar:

Copy code The code is as follows:

Buffer.isEncoding(encoding)

Receive parameters:

encoding {String} The detected encoding format

Example:

Copy code The code is as follows:

var a = Buffer.isEncoding('base64');

console.log(a);

Source code:

Copy code The code is as follows:

Buffer.isEncoding = function(encoding) {
switch ((encoding '').toLowerCase()) {
case 'hex':
case 'utf8':
case 'utf-8':
case 'ascii':
case 'binary':
case 'base64':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
case 'raw':
       return true;
Default:
Return false;
}
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn