NAME

UniEvent::Streamer - generic connector for read and write streams

SYNOPSIS

my $input    = UE::Streamer::FileInput->new("file.txt");
my $output   = UE::Streamer::StreamOutput->new($connection);
my $streamer = UE::Streamer->new($input, $output);
$streamer->start();
$streamer->finish_callback(sub { ... });

UE::Loop->default->run;

DESCRIPTION

Streamer redirects byte stream from input stream (aka producer) into output stream (aka consumer). It automatically synchronizes speed between input and output.

To use Streamer you need to create a streamer input and streamer output object. Those can be one of the built-in classes (see "BUILT-IN PRODUCERS AND CONSUMERS" in UniEvent::Streamer) or your own custom classes.

To create custom input and/or output you need to create a class that inherits from UniEvent::Streamer::Input or UniEvent::Streamer::Output. See those classes' docs for more details.

METHODS

new($input, $output, [$max_buf = 10_000_000], [$loop = default])

Constructs new Streamer object, connecting $input sink to $output. $max_buf is the buffer size (maximum amount of data to read-ahead from input). If output is not fast enough and this buffer gets full, then input is paused until some part of the buffer is processed by output.

NOTE: if you use inputs/outputs that works with handles (like StreamOutput/StreamInput), make sure that those handles that you pass to their constructor use loop $loop.

start()

Starts the streamer, i.e. start the process of reading from input and writing to output.

stop()

Interrupt streaming process. Callback will be called with UniEvent::SystemError::operation_canceled error.

finish_callback($sub)

finish_event()

Callback will be called upon completion of streaming process (successful or unsuccessful).

Callback signature:

my $error = shift;

Where $error (if any) is an object of class XS::ErrorCode.

See "EVENT CALLBACKS" in UniEvent

BUILT-IN PRODUCERS AND CONSUMERS

UniEvent::Streamer::FileInput

UniEvent::Streamer::FileOutput

UniEvent::Streamer::StreamInput

UniEvent::Streamer::StreamOutput