node.js中的buffer.toString方法使用說(shuō)明
方法說(shuō)明:
將buffer對(duì)象轉(zhuǎn)換成指定的字符編碼的字符串。
語(yǔ)法:
buffer.toString([encoding], [start], [end])
接收參數(shù):
encoding 轉(zhuǎn)換成字符串后的字符編碼,默認(rèn)為 ‘utf8′
start buffer 轉(zhuǎn)換的起始位置,默認(rèn)為 0
end buffer 轉(zhuǎn)換的結(jié)束位置,默認(rèn)為buffer長(zhǎng)度
例子:
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;
}
}
};
- 使用node.js中的Buffer類處理二進(jìn)制數(shù)據(jù)的方法
- Node.js中使用Buffer編碼、解碼二進(jìn)制數(shù)據(jù)詳解
- Node.js Windows Binary二進(jìn)制文件安裝方法
- node.js中Buffer緩沖器的原理與使用方法分析
- Node.js Buffer模塊功能及常用方法實(shí)例分析
- 詳解如何在Node.js的httpServer中接收前端發(fā)送的arraybuffer數(shù)據(jù)
- Node.js Buffer用法解讀
- 關(guān)于Node.js中Buffer的一些你可能不知道的用法
- 淺談Node.js:Buffer模塊
- Node.js實(shí)用代碼段之正確拼接Buffer
- Node.js實(shí)用代碼段之獲取Buffer對(duì)象字節(jié)長(zhǎng)度
- node.js中的buffer.copy方法使用說(shuō)明
- node.js中的buffer.fill方法使用說(shuō)明
- node.js中的buffer.length方法使用說(shuō)明
- node.js中的buffer.toJSON方法使用說(shuō)明
- node.js中的buffer.Buffer.isEncoding方法使用說(shuō)明
- node.js中的buffer.Buffer.isBuffer方法使用說(shuō)明
- node.js中的buffer.Buffer.byteLength方法使用說(shuō)明
- node.js中的buffer.slice方法使用說(shuō)明
- node.JS二進(jìn)制操作模塊buffer對(duì)象使用方法詳解
相關(guān)文章
node.js中使用node-schedule實(shí)現(xiàn)定時(shí)任務(wù)實(shí)例
這篇文章主要介紹了node.js中使用node-schedule實(shí)現(xiàn)定時(shí)任務(wù)實(shí)例,包括安裝方法和4種使用例子,需要的朋友可以參考下2014-06-06
手寫Node靜態(tài)資源服務(wù)器的實(shí)現(xiàn)方法
這篇文章主要介紹了手寫Node靜態(tài)資源服務(wù)器的實(shí)現(xiàn)方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
整理幾個(gè)關(guān)鍵節(jié)點(diǎn)深入理解nodejs
這篇文章主要介紹了整理幾個(gè)關(guān)鍵節(jié)點(diǎn)深入理解nodejs,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,需要的小伙伴可以參考一下,需要的小伙伴可以參考一下2022-07-07
package.json版本號(hào)符號(hào)^和~前綴的區(qū)別
這篇文章介紹了package.json版本號(hào)符號(hào)^和~前綴的區(qū)別,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06

