writable.writableLength 속성은 쓸 준비가 된 큐에 있는 바이트 또는 개체의 수를 표시하는 데 사용됩니다. highWaterMark에서 상태에 따라 데이터를 검사하는 데 사용됩니다.
구문
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입니다.