-require IO::File;
-use POSIX qw/dup/;
+# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
sub stream_to_string {
- my ($cb) = @_;
- my $headers;
- my $io = IO::File->new_tmpfile;
- my $dup = dup($io->fileno);
- my $response = sub { $headers = \@_, $io };
- $cb->($response);
- $io = IO::File->new;
- $io->fdopen($dup, 'r+');
- $io->seek(0, 0);
- $io->read(my $str, ($io->stat)[7]);
+ my ($res) = @_;
+ my $body = $res->[2];
+ my $str = '';
+ while (defined(my $chunk = $body->getline)) {
+ $str .= $chunk;
+ }
+ $body->close;
$str;
}
+
+1;