可讀流中的txt.properties屬性用於獲取聲明的可讀流的屬性編碼。此外,您可以使用可讀.setEncoding()方法設置此屬性。
用法:
readable.readableEncoding
返回值:它返回程序中使用的編碼。
以下示例說明了Node.js中visible.sensitiveEncoding屬性的使用:
範例1:
// Node.js program to demonstrate the
// readable.readableEncoding Property
// Include fs module
const fs = require("fs");
// Constructing readable stream
const readable = fs.createReadStream("input.text");
// Setting the encoding
readable.setEncoding("base64");
// Instructions for reading data
readable.on('readable', () => {
let chunk;
// Using while loop and calling
// read method with parameter
while (null !== (chunk = readable.read())) {
// Displaying the chunk
console.log(`read:${chunk}`);
}
});
// Calling readableEncoding property
readable.readableEncoding;
輸出:
read:aGVs read:bG8=
範例2:
// Node.js program to demonstrate the
// readable.readableEncoding Property
// Include fs module
const fs = require("fs");
// Constructing readable stream
const readable = fs.createReadStream("input.text");
// Setting the encoding
readable.setEncoding("hex");
// Instructions for reading data
readable.on('readable', () => {
let chunk;
// Using while loop and calling
// read method with parameter
while (null !== (chunk = readable.read())) {
// Displaying the chunk
console.log(`read:${chunk}`);
}
});
// Calling readableEncoding property
readable.readableEncoding;
輸出:
read:68656c6c6f
參考: https://nodejs.org/api/stream.html#stream_readable_readableencoding。
相關用法
- node.js Stream writable.writableHighWaterMark用法及代碼示例
- node.js Stream readable.readableObjectMode用法及代碼示例
- node.js Stream readable.readableLength用法及代碼示例
- node.js Stream writable.writableFinished用法及代碼示例
- node.js Stream writable.writableObjectMode用法及代碼示例
- node.js Stream writable.writableLength用法及代碼示例
- node.js Stream readable.readableHighWaterMark用法及代碼示例
- node.js Stream writable.writableEnded用法及代碼示例
- node.js Stream writable.destroyed用法及代碼示例
- node.js Stream readable.destroyed用法及代碼示例
- node.js Stream readable.readableEnded用法及代碼示例
- node.js Stream writable.writableCorked用法及代碼示例
- node.js Stream readable.readableFlowing用法及代碼示例
- node.js Stream writable.writable用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | Stream readable.readableEncoding Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。