2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 use IO::Handle (); # autoflush
6 use Fcntl qw(SEEK_SET);
7 use PublicInbox::TestCommon;
8 require_mods(qw(Compress::Zlib IO::Uncompress::Gunzip));
9 require_ok 'PublicInbox::GzipFilter';
12 open my $fh, '+>', undef or die "open: $!";
13 open my $dup, '>&', $fh or die "dup $!";
15 my $filter = PublicInbox::GzipFilter->new->attach($dup);
16 ok($filter->write("hello"), 'wrote something');
17 ok($filter->write("world"), 'wrote more');
19 seek $fh, 0, SEEK_SET;
20 IO::Uncompress::Gunzip::gunzip($fh => \(my $buf));
21 is($buf, 'helloworld', 'buffer matches');
25 pipe(my ($r, $w)) or die "pipe: $!";
28 my $filter = PublicInbox::GzipFilter->new->attach($w);
30 local $SIG{PIPE} = sub { $sigpipe = 1 };
31 open my $fh, '<', 'COPYING' or die "open(COPYING): $!";
32 my $buf = do { local $/; <$fh> };
33 while ($filter->write($buf .= rand)) {}
34 ok($sigpipe, 'got SIGPIPE') or diag "\$!=$!";