in reply to Archive::Zip - zip files are corrupted or invalid

When reading or writing binary files, always use binmode immediately after opening the filehandle.

... open my $fh, ">>", $fullpath or die $!; binmode $fh;

Also, when transferring a binary file, use "binary" mode in ftp.

Replies are listed 'Best First'.
Re^2: Archive::Zip - zip files are corrupted or invalid
by tomdbs98 (Beadle) on Jul 12, 2011 at 16:26 UTC
    Hi, thanks for the quick reply. I've made the change:
    open my $fh, ">>", $fullpath or die $!; binmode $fh; print $log "Writer error.\n" if $zip->writeToFileNamed( $fh ) != AZ_OK +; close $fh;
    But I still receive the same error on the file that is directly created by my script, not the one sent through ftp, so the binary mode in ftp wouldn't be the problem.
      $zip->writeToFileNamed( $fh )

      is likely wrong, at least when looking at Archive::Zip. You either want

      $zip->writeToFileHandle( $fh )

      or

      $zip->writeToFileNamed( $fullpath )

      Are you sure that you are looking at the correct file(s)? You also open $fh to append to $fullpath, which also strikes me as odd.

        oops! you're right, I should have been using:
        $zip->writeToFileHandle( $fh )
        I didn't see the distinction when looking through the docs.

        Also, I didn't catch that I was appending the the zip file because the filename is always supposed to be unique, but I will make that change as well.

        Thanks for your time, Tom