UniEvent::Streamer - generic connector for read and write streams
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;
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.
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.
$input
$output
$max_buf
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.
StreamOutput/StreamInput
$loop
Starts the streamer, i.e. start the process of reading from input and writing to output.
Interrupt streaming process. Callback will be called with UniEvent::SystemError::operation_canceled error.
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.
$error
See "EVENT CALLBACKS" in UniEvent
UniEvent::Streamer::FileInput
UniEvent::Streamer::FileOutput
UniEvent::Streamer::StreamInput
UniEvent::Streamer::StreamOutput
To install UniEvent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UniEvent
CPAN shell
perl -MCPAN -e shell install UniEvent
For more information on module installation, please visit the detailed CPAN module installation guide.