vertx.stream documentation

Functions that operate on Vert.x ReadStreams and WriteStreams.

on-data

(on-data stream handler)
Set a data handler on a ReadStream.
As data is read, the handler will be called with the data as a Buffer.
handler can either be a Handler or a single-arity fn.
Returns the stream.

on-drain

(on-drain stream handler)
Set a drain handler on a WriteStream.
If the write queue is full, then the handler will be called when
the write queue has been reduced to maxSize / 2.
handler can either be a Handler or a zero-arity fn.
Returns the stream.

on-end

(on-end stream handler)
Set an end handler on a ReadStream.
Once the stream has ended, and there is no more data to be read,
this handler will be called.
handler can either be a Handler or a zero-arity fn.
Returns the stream.

on-exception

(on-exception stream handler)
Set an exception handler on a stream.
handler can either be a Handler or a single-arity fn that will be
passed the exception.
Returns the stream.

pump

(pump read-stream write-stream)(pump read-stream write-stream start?)
Creates a Pump instance.

A Pump pumps data from a ReadStream to a WriteStream and performs
flow control where necessary to prevent the write stream buffer
from getting overfull.

Read bytes from a ReadStream and writes them to a WriteStream. If
data can be read faster than it can be written this could result in
the write queue of the WriteStream growing without bound,
eventually causing it to exhaust all available RAM.

To prevent this, after each write, it checks whether the write
queue of the WriteStream is full, and if so, the ReadStream is
paused, and a drainHandler is set on the WriteStream. When the
WriteStream has processed half of its backlog, the
drainHandler will be called, which results in the pump resuming
the ReadStream.

If start? is true (the default), the Pump will be started.

write

(write stream data)(write stream data-str enc)
Write data to the stream.
data can anything bufferable (see vertx.buffer).