ReadStream

Represents a stream of items that can be read from.

Any class that implements this interface can be used by a @see \io\vertx\jphp\core\streams\Pump to pump data from it to a @see \io\vertx\jphp\core\streams\WriteStream.

Streaming mode

The stream is either in flowing or fetch mode.
    Initially the stream is in flowing mode.
  • When the stream is in flowing mode, elements are delivered to the handler.
  • When the stream is in fetch mode, only the number of requested elements will be delivered to the handler.
The mode can be changed with the @see \io\vertx\jphp\core\streams\ReadStream::pause, @see \io\vertx\jphp\core\streams\ReadStream::resume and @see \io\vertx\jphp\core\streams\ReadStream::fetch methods:
  • Calling @see \io\vertx\jphp\core\streams\ReadStream::resume sets the flowing mode
  • Calling @see \io\vertx\jphp\core\streams\ReadStream::pause sets the fetch mode and resets the demand to 0
  • Calling @see \io\vertx\jphp\core\streams\ReadStream::fetch requests a specific amount of elements and adds it to the actual demand
package

Default

Methods

__construct

__construct() 

Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

endHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Set an exception handler on the read stream.

exceptionHandler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Fetch the specified <code>amount</code> of elements. If the <code>ReadStream</code> has been paused, reading will recommence with the specified <code>amount</code> of items, otherwise the specified <code>amount</code> will be added to the current stream demand.

fetch( $arg0) : $this

Arguments

$arg0

integer

Response

$this

a reference to this, so the API can be used fluently

Set a data handler. As data is read, the handler will be called with the data.

handler( $arg0) : $this

Arguments

$arg0

callable

Response

$this

a reference to this, so the API can be used fluently

Pause the <code>ReadStream</code>, it sets the buffer in <code>fetch</code> mode and clears the actual demand.

pause() : $this

While it's paused, no data will be sent to the data handler.

Response

$this

a reference to this, so the API can be used fluently

Pause this stream and return a @see \io\vertx\jphp\core\streams\Pipe to transfer the elements of this stream to a destination @see \io\vertx\jphp\core\streams\WriteStream.

pipe() : \io\vertx\jphp\core\streams\Pipe<T>

The stream will be resumed when the pipe will be wired to a WriteStream.

Response

\io\vertx\jphp\core\streams\Pipe

a pipe

Like @see \io\vertx\jphp\core\streams\ReadStream::pipeTo but with no completion handler.

pipeTo( $arg0,  $arg1 = null) : void

param $dst [WriteStream] pipeTo($dst)

Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result. param $dst [WriteStream] the destination write stream param $handler [callable] pipeTo($dst, $handler)

Arguments

$arg0

WriteStream

$arg1

callable

Resume reading, and sets the buffer in <code>flowing</code> mode.

resume() : $this

If the ReadStream has been paused, reading will recommence on it.

Response

$this

a reference to this, so the API can be used fluently