writable.writableCorked屬性是Stream模塊的內置應用程序編程接口,該接口用於檢查調用uncork()函數所需的次數,以便完全取消插播流。
用法:
writable.writableCorked
返回值:它返回一個表示可寫次數的整數值。需要調用uncork()。
以下示例說明了Node.js中writable.writableCorked屬性的使用:
範例1:
// Node.js program to demonstrate the
// writable.writableCorked Property
// Accessing stream module
const stream = require('stream');
// Creating a stream and creating
// a write function
const writable = new stream.Writable({
// Write function with its
// parameters
write:function(chunk, encoding, next) {
// Converting the chunk of
// data to string
console.log(chunk.toString());
next();
}
});
// Calling cork function
writable.cork();
// Writing data
writable.write('hi');
// Again calling cork function
writable.cork();
// Again writing some data
writable.write('GFG');
// Calling writable.writableCorked
// Property
writable.writableCorked;
輸出:
2
範例2:
// Node.js program to demonstrate the
// writable.writableCorked Property
// Accessing stream module
const stream = require('stream');
// Creating a stream and creating
// a write function
const writable = new stream.Writable({
// Write function with its
// parameters
write:function(chunk, encoding, next) {
// Converting the chunk of
// data to string
console.log(chunk.toString());
next();
}
});
// Calling cork function
writable.cork();
// Writing data
writable.write('hi');
// Calling uncork() function
writable.uncork();
// Again calling cork function
writable.cork();
// Again writing some data
writable.write('GFG');
// Calling writable.writableCorked
// Property
writable.writableCorked;
輸出:
hi 1
在上麵的示例中,我們已經調用了uncork()函數一次。因此,為了完全解開流,您隻需要調用uncork()函數一次,輸出為1。
參考: https://nodejs.org/api/stream.html#stream_writable_writablecorked
相關用法
- node.js Stream writable.writableLength用法及代碼示例
- node.js Stream writable.destroyed用法及代碼示例
- node.js Stream writable.writableEnded用法及代碼示例
- node.js Stream readable.destroyed用法及代碼示例
- node.js Stream writable.writableHighWaterMark用法及代碼示例
- node.js Stream writable.writableFinished用法及代碼示例
- node.js Stream writable.writableObjectMode用法及代碼示例
- node.js Stream readable.readable用法及代碼示例
- node.js Stream writable.writable用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | Stream writable.writableCorked Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。