Is there any way in perl to check integrity of gz and zip files without calling external gz or unzip?
The gzip and unzip binaries have a -t option to allow checking integrity.
Currently using Archive::Zip for unzipping and IO::Uncompress::Gunzip for uncompressing gz files. Would like to check the integrity of the file before attempting uncompression or extraction. I'm already checking the file is the correct type by using File:Type and checking the mime type. This will ensure the file is of the correct type but won't check for corruption of the file past the header.
Any help here would be appreciated
my $ft = File::Type->new();
my $type = $ft->mime_type($filename);
if ( $type eq "application/zip" ) {
.....
}
if ( $type eq "application/x-gzip" ) {
....
}
Options for gz and unzip
$ gzip -h
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).
.....
-t, --test test compressed file integrity
....
$ unzip -h
...
Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d
+exdir]
Default action is to extract files in list, except those in xlist, t
+o exdir;
file[.zip] may be a wildcard. -Z => ZipInfo mode ("unzip -Z" for us
+age).
...
-f freshen existing files, create none -t test compressed archi
+ve data
..