A readable stream.

This is an abstract base class that should never be used directly. Instead, subclasses should override the internalRead method.

Constructor

private@:value({ highWaterMark : 8192 })@:dox(show)new (highWaterMark:Int = 8192)

Variables

@:value(0)read onlybufferLength:Int = 0

Total amount of data currently in the internal buffer, in bytes.

@:value(false)read onlydone:Bool = false

Whether this stream is finished. When true, no further signals will be emmited by this instance.

@:value(new ArraySignal())errorSignal:Signal<Error> = new ArraySignal()

@:value(false)read onlyflowing:Bool = false

Whether data is flowing at the moment. When flowing, data signals will be emitted and the internal buffer will be empty.

@:value(8192)highWaterMark:Int = 8192

High water mark. Readable will call internalRead pre-emptively to fill up the internal buffer up to this value when possible. Set to 0 to disable pre-emptive reading.

@:value(new ArraySignal())pauseSignal:Signal<NoData> = new ArraySignal()

@:value(new ArraySignal())resumeSignal:Signal<NoData> = new ArraySignal()

Methods

private@:dox(show)asyncRead (chunks:Array<Bytes>, eof:Bool):Void

This method should be used internally from internalRead to provide data resulting from asynchronous operations. The arguments to this method are the same as ReadableResult.Data. See internalRead for more details.

private@:dox(show)internalRead (remaining:Int):ReadResult

This method should be overridden by a subclass.

This method will be called as needed by Readable. The remaining argument is an indication of how much data is needed to fill the internal buffer up to the high water mark, or the current requested amount of data. This method is called in a cycle until the read cycle is stopped with a None return or an EOF is indicated, as described below.

If a call to this method returns None, the current read cycle is ended. This value should be returned when there is no data available at the moment, but a read request was scheduled and will later be fulfilled by a call to asyncRead.

If a call to this method returns Data(chunks, eof), chunks will be added to the internal buffer. If eof is true, the read cycle is ended and the readable stream signals an EOF (end-of-file). After an EOF, no further calls will be made. chunks should not be an empty array if eof is false.

Code inside this method should only call asyncRead (asynchronously from a callback) or provide data using the return value.