NAME

Streams - Streams for Perl

SYNOPSIS

use Streams;
$rs = ReadableStream->new (...);
$ws = WritableStream->new (...);

DESCRIPTION

The Streams module loads ReadableStream and WritableStream classes and additional utilities.

By useing this module, following classes are available:

ReadableStream
WritableStream

The perl-streams Git repository also has a subset of Perl variant of Typed Array API, which consists of following modules:

ArrayBuffer
TypedArray
DataView

For convinience, TypedArray and DataView objects are instances of the ArrayBufferView class.

There are also Streams::Filehandle, Streams::IOError, and Streams::Devel.

QUEUING STRATEGY

Both ReadableStream and WritableStream constructors receive optional queuing strategy. A queuing strategy is a hash reference with two key/value pairs:

high_water_mark => $number

The expected queue size. The value must be a positive number.

size => CODE

A CODE returning the size of a chunk.

The code is invoked with an argument. The code is expected to return the size of that value.

Following functions constructing queuing strategies are available:

$strategy = Streams::ByteLengthQueuingStrategy {high_water_mark => $number}

Return a new queuing strategy using byte length of chunks. The argument must be a hash reference whose high_water_mark is the expected byte length of the buffer.

$strategy = Streams::CountingQueuingStrategy {high_water_mark => $number}

Return a new queuing strategy using the number of chunks. The argument must be a hash reference whose high_water_mark is the expected number of chunks in the queue.

These are expected to be equivalent to JavaScript Streams API, as specified by WHATWG Streams Standard (except for language differences).

DEPENDENCY

Perl 5.10 or later is required. The Scalar::Util module, which is a core module, is required.

These modules depend on Promise <https://github.com/manakai/perl-promise>.

AVAILABILITY

The latest version of these modules are available at <https://github.com/manakai/perl-streams>.

SEE ALSO

Streams Standard <https://streams.spec.whatwg.org/>.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2017-2021 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.