Stream
Module | ejs |
Definition | class Stream |
Specified | evolving |
Stream objects represent bi-directional streams of data that pass data elements between an endpoint known as a source or sink and a consumer / producer.
In between, intermediate streams may be used as filters. Example endpoints are the File, Socket, String and Http classes. The TextStream is an example of a filter stream. The data elements passed by streams may be any series of objects including: bytes, lines of text, integers or objects. Streams may buffer the incoming data or not. Streams may offer sync and/or async modes of operation.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
No properties defined |
Stream Methods
Qualifiers | Method |
---|---|
public | close(graceful: Boolean = false): Void |
Close the input stream and free up all associated resources. | |
public | flush(graceful: Boolean = true): Void |
Flush the stream and all stacked streams and underlying data source/sinks. | |
public | read(buffer: ByteArray, offset: Number = 0 , count: Number = -1): Number |
Read a block of data from the stream. | |
public | write(data: Array): Number |
Write data to the stream. |
Method Detail
Close the input stream and free up all associated resources.
- Description
- WARNING: This API will have the graceful parameter removed in a future release. Call flush manually if you require graceful closes.
- Parameters
graceful: Boolean If true, then close the socket gracefully after writing all pending data. [default: false]
Flush the stream and all stacked streams and underlying data source/sinks.
- Description
- WARNING: This API will have the graceful parameter removed in a future release. All flushes will then be graceful.
- Parameters
graceful: Boolean If true, then write all pending data. [default: true]
Read a block of data from the stream.
- Description
- Read the required number of bytes from the stream into the supplied byte array at the given offset.
- Parameters
buffer: ByteArray Destination byte array for read data. offset: Number Offset in the byte array to place the data. If the offset is -1, then data is appended to the buffer write position which is then updated. [default: 0 ] count: Number Number of bytes to read. If -1, read as much as the buffer will hold up to the entire stream if the buffer is of sufficient size or is growable. [default: -1]
- Returns
- A count of the bytes actually read.
- Throws
- IOError: if an I/O error occurs.
Write data to the stream.
- Description
- If in sync mode, the write call blocks until the underlying stream or endpoint absorbes all the data. If in async-mode, the call accepts whatever data can be accepted immediately and returns a count of the elements that have been written.
- Parameters
data: Array Data to write.
- Returns
- The total number of elements that were written.
- Throws
- IOError: if there is an I/O error.