writable.writableLength বৈশিষ্ট্যটি লেখার জন্য প্রস্তুত সারিতে থাকা বাইট বা বস্তুর সংখ্যা প্রদর্শনের জন্য ব্যবহৃত হয়। এটি হাইওয়াটারমার্কের স্ট্যাটাস অনুযায়ী ডেটা পরিদর্শনের জন্য ব্যবহৃত হয়।
সিনট্যাক্স
writeable.writableLength
উদাহরণ 1
নাম সহ একটি ফাইল তৈরি করুন – writableLength.js এবং নীচের কোড স্নিপেটটি অনুলিপি করুন। ফাইল তৈরি করার পরে, নীচের উদাহরণে দেখানো এই কোডটি চালানোর জন্য নিম্নলিখিত কমান্ডটি ব্যবহার করুন −
node writableLength.js
// Program to demonstrate writable.writableLength method
const stream = require('stream');
// Creating a data stream with writable
const writable = new stream.Writable({
// Writing the data from stream
write: function(chunk, encoding, next) {
// Converting the data chunk to be displayed
console.log(chunk.toString());
next();
}
});
// Writing data - Not in the buffer queue
writable.write('Hi - This data will not be counted');
// Calling the cork() function
writable.cork();
// Again writing some data
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');
writable.write('This data will be corked in the memory');
// Printing the length of the queue data
console.log(writable.writableLength); আউটপুট
C:\home\node>> node writableLength.js Hi - This data will not be counted 81
কার্ক করা এবং বাফার সারির ভিতরে থাকা ডেটা কনসোলে গণনা করা হয় এবং প্রিন্ট করা হয়।
উদাহরণ
আসুন আরও একটি উদাহরণ দেখি।
// Program to demonstrate writable.cork() method
const stream = require('stream');
// Creating a data stream with writable
const writable = new stream.Writable({
// Writing the data from stream
write: function(chunk, encoding, next) {
// Converting the data chunk to be displayed
console.log(chunk.toString());
next();
}
});
// Writing data - Not in the buffer queue
writable.write('Hi - This data will not be counted');
// Calling the cork() function
writable.cork();
// Again writing some data
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');
writable.write('This data will be corked in the memory');
// Printing the length of the queue data
console.log(writable.writableLength);
// Flushing the data from buffered memory
writable.uncork()
console.log(writable.writableLength); আউটপুট
C:\home\node>> node writableLength.js Hi - This data will not be counted 81 Welcome to TutorialsPoint ! SIMPLY LEARNING This data will be corked in the memory 0
যেহেতু ডেটা এখন uncork() এর পরে ফ্লাশ করা হয়েছে। সারিতে কোনো ডেটা থাকবে না, যার কারণে দৈর্ঘ্য 0।