]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: gzip_filter: implicitly flush {obuf} on zmore/zflush
authorEric Wong <e@80x24.org>
Sat, 10 Sep 2022 08:16:53 +0000 (08:16 +0000)
committerEric Wong <e@80x24.org>
Sat, 10 Sep 2022 19:50:25 +0000 (19:50 +0000)
This seems like the least disruptive way to allow more use of
->zmore when streaming large messages to sockets.

lib/PublicInbox/CompressNoop.pm
lib/PublicInbox/GzipFilter.pm
lib/PublicInbox/ViewVCS.pm

index e3301473626187b8171fc4613180a0caf0ca4f4b..5135299f0ab9aaace5e2a560cb31277756c37c25 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Provide the same methods as Compress::Raw::Zlib::Deflate but
@@ -10,7 +10,7 @@ use Compress::Raw::Zlib qw(Z_OK);
 sub new { bless \(my $self), __PACKAGE__ }
 
 sub deflate { # ($self, $input, $output)
-       $_[2] .= $_[1];
+       $_[2] .= ref($_[1]) ? ${$_[1]} : $_[1];
        Z_OK;
 }
 
index 86d34183597892cc2a7c252d430fc22c718d839e..75ba625ed02c9987bb5a05d67dbb7a58a090b4b1 100644 (file)
@@ -140,8 +140,8 @@ sub zmore {
        my $self = $_[0]; # $_[1] => input
        http_out($self);
        my $err;
-       for (1..$#_) {
-               $err = $self->{gz}->deflate($_[$_], $self->{zbuf});
+       for (delete $self->{obuf}, @_[1..$#_]) {
+               $err = $self->{gz}->deflate($_ // next, $self->{zbuf});
                die "gzip->deflate: $err" if $err != Z_OK;
        }
        undef;
@@ -153,8 +153,9 @@ sub zflush ($;@) {
        my $zbuf = delete $self->{zbuf};
        my $gz = delete $self->{gz};
        my $err;
-       for (1..$#_) { # it's a bug iff $gz is undef w/ $_[1..]
-               $err = $gz->deflate($_[$_], $zbuf);
+       # it's a bug iff $gz is undef w/ $obuf or $_[1..]
+       for (delete $self->{obuf}, @_[1..$#_]) {
+               $err = $gz->deflate($_ // next, $zbuf);
                die "gzip->deflate: $err" if $err != Z_OK;
        }
        $gz // return ''; # not a bug, recursing on DS->write failure
index 3b4fa393ed3ff16436db04a0dc3259d62825edbf..ed4a645451176be47a38d9ccaa359907f114034f 100644 (file)
@@ -210,8 +210,6 @@ EOM
                $x =~ s/\r?\n/\n/gs;
                $ctx->{-anchors} = {} if $x =~ /^diff --git /sm;
                flush_diff($ctx, \$x); # undefs $x
-               $ctx->zmore($bdy);
-               undef $bdy;
                # TODO: should there be another textarea which attempts to
                # search for the exact email which was applied to make this
                # commit?