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 ..

In reply to File integrity checker by roperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.