Node.js Stream writable.writableLength Property
Last Updated :
05 Aug, 2022
The writable.writableLength property is an inbuilt application of stream module which is used to check the number of bytes in the queue that is ready to be written.
Syntax:
writable.writableLength
Return Value: This property returns the number of bytes that is ready to write into the queue.
Below examples illustrate the use of writable.writableLength property in Node.js:
Example 1:
javascript
const stream = require( 'stream' );
const writable = new stream.Writable({
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.cork();
writable.write( 'hi' );
writable.write( 'GFG' );
console.log(writable.writableLength);
|
Output:
5
Example 2:
javascript
const stream = require( 'stream' );
const writable = new stream.Writable({
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.cork();
writable.write( 'hi' );
writable.uncork();
writable.cork();
writable.write( 'GFG' );
console.log(writable.writableLength);
|
Output:
hi
3
Here, the data ‘hi’ is not present in buffer anymore So, the buffer has only 3 bytes present data ‘GFG’ takes 3 bytes.
Reference: https://nodejs.org/api/stream.html#stream_writable_writablelength
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...