new WriteStream()
Represents a stream of data that can be written to.
- Source:
Methods
-
drainHandler(handler) → {WriteStream}
-
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize / 2. See Pump for an example of this being used.
Parameters:
Name Type Description handler
function the handler - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- WriteStream
-
exceptionHandler(handler) → {WriteStream}
-
Set an exception handler on the write stream.
Parameters:
Name Type Description handler
function the exception handler - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- WriteStream
-
setWriteQueueMaxSize(maxSize) → {WriteStream}
-
Set the maximum size of the write queue to
maxSize
. You will still be able to write to the stream even if there is more thanmaxSize
bytes in the write queue. This is used as an indicator by classes such asPump
to provide flow control.Parameters:
Name Type Description maxSize
number the max size of the write stream - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- WriteStream
-
write(data) → {WriteStream}
-
Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the WriteStream#writeQueueFull method before writing. This is done automatically if using a Pump.
Parameters:
Name Type Description data
Object the data to write - Source:
Returns:
a reference to this, so the API can be used fluently- Type
- WriteStream
-
writeQueueFull() → {boolean}
-
This will return
true
if there are more bytes in the write queue than the value set using WriteStream#setWriteQueueMaxSize- Source:
Returns:
true if write queue is full- Type
- boolean