Stream
Module | ejs |
Namespace | intrinsic |
Definition | class Stream |
Specified | Ejs-11. |
Inheritance | Stream |
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 | available(): Number |
Return the number of bytes available to read. | |
public | close(graceful: Boolean): Void |
Close the input stream and free up all associated resources. | |
public | flush(): Void |
Flush the stream and all stacked streams and underlying data source/sinks. | |
public | read(buffer: ByteArray, offset: Number, count: Number): Number |
Read a block of data from the stream. | |
public | skip(n: Number): Void |
public | write(data: Array): Number |
Write data to the stream. |
Method Detail
Return the number of bytes available to read.
- Returns
- A the number of available bytes.
Close the input stream and free up all associated resources.
- 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.
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.