]> Sergey Matveev's repositories - public-inbox.git/commitdiff
gzip_filter: ->zmore and ->zflush support multiple args
authorEric Wong <e@80x24.org>
Tue, 23 Aug 2022 08:32:02 +0000 (08:32 +0000)
committerEric Wong <e@80x24.org>
Tue, 23 Aug 2022 22:40:57 +0000 (22:40 +0000)
This will make writev-like use easier for the next commit,
and also future changes where I'll rely more on zlib for
buffering.

lib/PublicInbox/GzipFilter.pm

index bdd313f5a799c5f003adb61ea205219d85b60281..86d34183597892cc2a7c252d430fc22c718d839e 100644 (file)
@@ -139,19 +139,22 @@ sub write {
 sub zmore {
        my $self = $_[0]; # $_[1] => input
        http_out($self);
-       my $err = $self->{gz}->deflate($_[1], $self->{zbuf});
-       die "gzip->deflate: $err" if $err != Z_OK;
+       my $err;
+       for (1..$#_) {
+               $err = $self->{gz}->deflate($_[$_], $self->{zbuf});
+               die "gzip->deflate: $err" if $err != Z_OK;
+       }
        undef;
 }
 
 # flushes and returns the final bit of gzipped data
-sub zflush ($;$) {
-       my $self = $_[0]; # $_[1] => final input (optional)
+sub zflush ($;@) {
+       my $self = $_[0]; # $_[1..Inf] => final input (optional)
        my $zbuf = delete $self->{zbuf};
        my $gz = delete $self->{gz};
        my $err;
-       if (defined $_[1]) { # it's a bug iff $gz is undef w/ $_[1]
-               $err = $gz->deflate($_[1], $zbuf);
+       for (1..$#_) { # it's a bug iff $gz is undef w/ $_[1..]
+               $err = $gz->deflate($_[$_], $zbuf);
                die "gzip->deflate: $err" if $err != Z_OK;
        }
        $gz // return ''; # not a bug, recursing on DS->write failure