国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

node.js中的buffer.toString方法使用說明

2019-11-20 13:45:16
字體:
來源:轉載
供稿:網友

方法說明:

將buffer對象轉換成指定的字符編碼的字符串。

語法:

復制代碼 代碼如下:

buffer.toString([encoding], [start], [end])

接收參數:

encoding       轉換成字符串后的字符編碼,默認為 ‘utf8′

start                buffer 轉換的起始位置,默認為 0

end                 buffer 轉換的結束位置,默認為buffer長度

例子:

復制代碼 代碼如下:

var b = new Buffer(50);
 
console.log(b);
 
var c = b.toString('base64',0,10);
 
console.log(c);

源碼:

復制代碼 代碼如下:

// toString(encoding, start=0, end=buffer.length)
Buffer.prototype.toString = function(encoding, start, end) {
  var loweredCase = false;
  start = start >>> 0;
  end = util.isUndefined(end) ? this.length : end >>> 0;
  if (!encoding) encoding = 'utf8';
  if (start < 0) start = 0;
  if (end > this.length) end = this.length;
  if (end <= start) return '';
  while (true) {
    switch (encoding) {
      case 'hex':
        return this.hexSlice(start, end);
      case 'utf8':
      case 'utf-8':
        return this.utf8Slice(start, end);
      case 'ascii':
        return this.asciiSlice(start, end);
      case 'binary':
        return this.binarySlice(start, end);
      case 'base64':
        return this.base64Slice(start, end);
      case 'ucs2':
      case 'ucs-2':
      case 'utf16le':
      case 'utf-16le':
        return this.ucs2Slice(start, end);
      default:
        if (loweredCase)
          throw new TypeError('Unknown encoding: ' + encoding);
        encoding = (encoding + '').toLowerCase();
        loweredCase = true;
    }
  }
};

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 郯城县| 剑河县| 台东县| 凤翔县| 江阴市| 秦安县| 黄浦区| 保康县| 云阳县| 凤山县| 新晃| 库尔勒市| 乌恰县| 纳雍县| 视频| 峨山| 惠安县| 台湾省| 从化市| 江都市| 永昌县| 兴安县| 万荣县| 通许县| 兴宁市| 定日县| 巢湖市| 尼勒克县| 阿图什市| 江口县| 蛟河市| 赞皇县| 南涧| 南阳市| 区。| 乾安县| 石屏县| 龙井市| 天门市| 香格里拉县| 桐庐县|