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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。