senthil_v has asked for the wisdom of the Perl Monks concerning the following question:

Senthil

Good Day All,

Can you please help on this issue? I had tried to extract the files from Zip. due to some reason that script does not extract the files from zip file which returned the below error.

Error Details:

format error: bad signature: 0x00000000 at offset 568276 in file AUS-000X-201512 28234755_Data.zip at C:/Perl64/lib/Archive/Zip.pm line 477.Archive::Zip::_readSignature('IO::File=GLOB(0x2a5e2a8)', 'AUS-000X-20151228234755_Data.zip') called at C:/Perl64/lib/Archive/Zip/Archive.pm line 603 Archive::Zip::Archive::readFromFileHandle('Archive::Zip::Archive=HASH(0x32c1e8)', 'IO::File=GLOB(0x2a5e2a8)', 'AUS-000X-20151228234755_Data.zip') called at C:/Perl64/lib/Archive/Zip/Archive.pm line 548 Archive::Zip::Archive::read('Archive::Zip::Archive=HASH(0x32c1e8)', 'AUS-000X-20151228234755_Data.zip') called at zip_extraction.pl line 14 Read of AUS-000X-20151228234755_Data.zip failed

use strict; use Archive::Zip qw(:ERROR_CODES); opendir(DIR, "C:\\Users\\vinayas1\\Desktop\\Automation") || die "Can't + open local directory : $!"; my @zips = grep { -f "./$_" } readdir (DIR); close(DIR); foreach my $zipfiles (grep( /\.zip$/,@zips)) { print "$zipfiles\n"; if ($zipfiles =~ /\w+\.zip$/) { my $zip = Archive::Zip->new(); my $zipName = "$zipfiles"; my $status = $zip->read( $zipName); die "Read of $zipName failed\n" if $status != AZ_OK; print "$zipfiles\n"; $zip->extractTree(); #unlink($zipfiles); } }

Thanks in Advance,

Senthil. V

Replies are listed 'Best First'.
Re: Unable to Extract the Zip file
by FloydATC (Deacon) on Dec 29, 2015 at 09:28 UTC
    As far as I can tell, your code should work as expected.

    I would first double-check that AUS-000X-201512 28234755_Data.zip is in fact a valid Zip archive and not some other compressed format which is transparently recognized and handled by whatever tool you are using when manually opening it. The quickest way to check is to open the file in a text editor and check the first two bytes. They will usually read "PK", followed by unreadable characters. (See https://en.wikipedia.org/wiki/Zip_%28file_format%29)

    If the file is indeed a Zip archive, my guess is that your Archive::Zip module or one of its dependencies needs an update.

    -- FloydATC

    Time flies when you don't know what you're doing

      Thanks Floyd. i had opened the zip file in editor and could see that 'PK' character is being appeared at the first line followed by unreadble character. really, i am wondering that why it is not able to exrtact the content.

      Thanks,

      Senthil

Re: Unable to Extract the Zip file
by Discipulus (Canon) on Dec 29, 2015 at 10:22 UTC
    just some sparse toughts:
    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Thanks Discipulus, finally, i am able to extract the content by IO::Uncompress::Unzip module. it does works really fine. Thank you once again.. hence, i am closing the thread.

        Coming to this late, but if the zip file can be read by IO::Uncompress::Unzip but not by Archive::Zip, then it is likely to be one of the following things

        1 - The archive uses Zip64

        Usually used when the archive is >4Gig, but can sometimes be always set by some programs that write zip files. Archive::Zip doesn't support Zip64 yet, but IO::Uncompress::Unzip does.

        2 - The central directory of the zip file is corrupt.

        Archive::Zip needs the central directory in the zip file to be present and valid. The approach I take with IO::Uncompress::Unzip doesn't actually use the central directory at all. This one is unlikely.

        Without seeing the file I suspect it is Zip64.

        Paul

Re: Unable to Extract the Zip file
by Corion (Patriarch) on Dec 29, 2015 at 10:01 UTC

    The error message reads to me as if the file contents are corrupted. I would try to verify the file integrity using other programs like unzip or 7zip. Maybe you can rescue some file contents or ask for a retransmission of the original file.

Re: Unable to Extract the Zip file (ziptest.pl)
by Anonymous Monk on Dec 29, 2015 at 09:27 UTC

      Thanks for your reply. i have ran the code as you given by the link. but still issue has persist as it was returned same error. please guide me for other option to resolve the issue.

      Thanks,

      Senthil. V

        Thanks for your reply. i have ran the code as you given by the link. but still issue has persist as it was returned same error. please guide me for other option to resolve the issue.

        I asked you to try three things, other programs (zip), and 7zip, and ziptest.pl

        If all three programs say the file isn't zip, your search is over, nothing left to do, problem is the file