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

  • 2020-05-05 10:53:10
  • OfStack

method description:

Checks for a valid encoding parameter and returns true or false.

syntax:


Buffer.isEncoding(encoding)

receive parameters:

encoding {String}     is detected in the encoding format

example:


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

source:


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;
  }
};


Related articles: