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

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