tokuhirom's Blog

urandom streaming on twiggy

use strict;
use warnings;
use autodie;

sub {
    open my $fh, '<', '/dev/urandom';
    sub {
        my $respond = shift;
        my $writer = $respond->([200, ['Content-Type' => 'application/octet-stream']]);
        while (1) {
            read $fh, my $buf, 1024;
            $writer->write($buf);
        }
    };
};