Mastering Node.Js | Writable Stream in Node.js
Автор: Aadarsh - The Coder
Загружено: 2025-05-02
Просмотров: 58
All streams created by Node.js APIs operate exclusively on strings, Buffer TypedArray and DataView objects:
Strings and Buffers are the most common types used with streams.
TypedArray and DataView lets you handle binary data with types like Int32Array or Uint8Array. When you write a TypedArray or DataView to a stream, Node.js processes the raw bytes.
It is possible, however, for stream implementations to work with other types of JavaScript values (with the exception of null, which serves a special purpose within streams). Such streams are considered to operate in "object mode".
Stream instances are switched into object mode using the objectMode option when the stream is created. Attempting to switch an existing stream into object mode is not safe.
Buffering#
Both Writable and Readable streams will store data in an internal buffer.
The amount of data potentially buffered depends on the highWaterMark option passed into the stream's constructor. For normal streams, the highWaterMark option specifies a total number of bytes. For streams operating in object mode, the highWaterMark specifies a total number of objects. For streams operating on (but not decoding) strings, the highWaterMark specifies a total number of UTF-16 code units.
Data is buffered in Readable streams when the implementation calls stream.push(chunk). If the consumer of the Stream does not call stream.read(), the data will sit in the internal queue until it is consumed.
Once the total size of the internal read buffer reaches the threshold specified by highWaterMark, the stream will temporarily stop reading data from the underlying resource until the data currently buffered can be consumed (that is, the stream will stop calling the internal readable._read() method that is used to fill the read buffer).
Data is buffered in Writable streams when the writable.write(chunk) method is called repeatedly. While the total size of the internal write buffer is below the threshold set by highWaterMark, calls to writable.write() will return true. Once the size of the internal buffer reaches or exceeds the highWaterMark, false will be returned.
Thank you for watching this video. follow me a social media for letest updates.
follow me 👇
Website: https://thecoder.in
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: