源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-10-15 05:13 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:node.js中的buffer.toString方法使用说明
[b]方法说明:[/b] 将buffer对象转换成指定的字符编码的字符串。 [b]语法:[/b]
[u]复制代码[/u] 代码如下:
buffer.toString([encoding], [start], [end])
[b]接收参数:[/b] encoding       转换成字符串后的字符编码,默认为 ‘utf8′ start                buffer 转换的起始位置,默认为 0 end                 buffer 转换的结束位置,默认为buffer长度 [b]例子:[/b]
[u]复制代码[/u] 代码如下:
var b = new Buffer(50);   console.log(b);   var c = b.toString('base64',0,10);   console.log(c);
[b]源码:[/b]
[u]复制代码[/u] 代码如下:
// 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;     }   } };
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部