use IO::Compress::Gzip qw(gzip);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
my $data = 'I include only the bare bones because I tried something';
# Create some compressed data
my $gzipped ;
gzip \$data => \$gzipped ;
####
my $corrupt = $gzipped;
# Overwrite part of the compressed data with junk
substr($corrupt, 10, 3, "BAD") ;
gunzip \$corrupt => \$uncompressed
or print "Cannot gunzip: $GunzipError\n";
####
Cannot gunzip: Inflation Error: data error
####
# truncate the compressed data
my $truncated = substr($gzipped, 0, 10);
gunzip \$truncated => \$uncompressed
or print "Cannot gunzip: $GunzipError\n";
####
Cannot gunzip: unexpected end of file