diff options
author | Eric Wong <e@yhbt.net> | 2020-03-21 02:03:44 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-03-25 01:48:34 +0000 |
commit | a71cb67a1237c450a9cbbd6738c5af3b73ba4c61 (patch) | |
tree | 514fd2f9f289622615069850828475c09fc8ecc4 /lib/PublicInbox/GetlineBody.pm | |
parent | decbb9936a25dfedf6ecd916d8e0403f06217ec9 (diff) | |
download | public-inbox-a71cb67a1237c450a9cbbd6738c5af3b73ba4c61.tar.gz |
We'll be supporting gzipped from sqlite3(1) dumps for altid files in future commits. In the future (and if we survive), we may replace Plack::Middleware::Deflater with our own GzipFilter to work better with asynchronous responses without relying on memory-intensive anonymous subs.
Diffstat (limited to 'lib/PublicInbox/GetlineBody.pm')
-rw-r--r-- | lib/PublicInbox/GetlineBody.pm | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/PublicInbox/GetlineBody.pm b/lib/PublicInbox/GetlineBody.pm index 92719a82..6becaaf5 100644 --- a/lib/PublicInbox/GetlineBody.pm +++ b/lib/PublicInbox/GetlineBody.pm @@ -13,13 +13,13 @@ use strict; use warnings; sub new { - my ($class, $rpipe, $end, $end_arg, $buf) = @_; + my ($class, $rpipe, $end, $end_arg, $buf, $filter) = @_; bless { rpipe => $rpipe, end => $end, end_arg => $end_arg, - buf => $buf, - filter => 0, + initial_buf => $buf, + filter => $filter, }, $class; } @@ -30,19 +30,18 @@ sub DESTROY { $_[0]->close } sub getline { my ($self) = @_; - my $filter = $self->{filter}; - return if $filter == -1; # last call was EOF - - my $buf = delete $self->{buf}; # initial buffer - $buf = $self->{rpipe}->getline unless defined $buf; - $self->{filter} = -1 unless defined $buf; # set EOF for next call + my $rpipe = $self->{rpipe} or return; # EOF was set on previous call + my $buf = delete($self->{initial_buf}) // $rpipe->getline; + delete($self->{rpipe}) unless defined $buf; # set EOF for next call + if (my $filter = $self->{filter}) { + $buf = $filter->translate($buf); + } $buf; } sub close { my ($self) = @_; - my ($rpipe, $end, $end_arg) = delete @$self{qw(rpipe end end_arg)}; - close $rpipe if $rpipe; + my ($end, $end_arg) = delete @$self{qw(end end_arg)}; $end->($end_arg) if $end; } |