archive::zip addtree creates zero-length files

archive::zip addtree creates zero-length files

am 06.11.2005 22:35:26 von Graham

I am using archive::zip with ActiveState Perl on Windows, and using
addtree to zip up folders. I observe that for each folder it zips, it
creates a file of the same name, zero bytes in length, in the archive.
If I open the archive in Windows Explorer (using the built in
compressed folders feature of Windows) and drag folders out, the
extract fails due to the zero length files.

Anybody else experienced this? Any solution to stop archive::zip from
creating these unwanted and problematic files?


my $zip = Archive::Zip->new(); # Create zip
die "Failed to zip $name" # Add contents
if $zip->addTree($item, $name) != AZ_OK;

#$member->desiredCompressionMethod( COMPRESSION_DEFLATED );
die "Failed to write $name.zip file"
if $zip->writeToFileNamed("$name.zip") != AZ_OK;


Thanks,

Graham
--
Graham Steel: graham@nospam.steelworks.org.uk
Web: http://www.steelworks.org.uk

Re: archive::zip addtree creates zero-length files

am 07.11.2005 00:57:30 von Sisyphus

"Graham" wrote in message
news:436be6e1.7507436@news.freenetname.co.uk...
> I am using archive::zip with ActiveState Perl on Windows, and using
> addtree to zip up folders. I observe that for each folder it zips, it
> creates a file of the same name, zero bytes in length, in the archive.
> If I open the archive in Windows Explorer (using the built in
> compressed folders feature of Windows) and drag folders out, the
> extract fails due to the zero length files.

Couldn't reproduce the problem. This worked fine for me (AS perl build 810):

use warnings;
use Archive::Zip;
$zip = Archive::Zip->new();
$zip->addTree( '.', '');
$zip->writeToFileNamed("test.zip");

It will pack all files in the current directory and below into a file named
test.zip .... so be a little judicious in selecting a directory to run it
from.

If you still experience difficulty, can you provide a complete minimal
script that demonstrates the problem.

Cheers,
Rob

Re: archive::zip addtree creates zero-length files

am 08.11.2005 22:21:52 von Graham

The sample program does exhibit the problem on my system. I am using
Perl build 805 rather than 810, but I downloaded Archive::Zip module
v1.16, because the older version provided with build 805 includes a
separate Tree module. If I zip up a sample tree using the script
below, the freeware infozip utility shows no problem with the
contents, but if I open the Compressed folder in Windows Explorer it
shows zero length files alongside the folders, with the same name as
the folders, and extraction fails. If I create the compressed folder
using the Windows built-in compressed folder functionality, it creates
a similar zip but without the zero length files.

On Mon, 7 Nov 2005 10:57:30 +1100, "Sisyphus"
wrote:

>Couldn't reproduce the problem. This worked fine for me (AS perl build 810):
>
>use warnings;
>use Archive::Zip;
>$zip = Archive::Zip->new();
>$zip->addTree( '.', '');
>$zip->writeToFileNamed("test.zip");
>

--
Graham Steel: graham@nospam.steelworks.org.uk
Web: http://www.steelworks.org.uk

Re: archive::zip addtree creates zero-length files

am 08.11.2005 23:21:04 von Sisyphus

"Graham" wrote in message
news:436fdfbd.5563466@news.freenetname.co.uk...
> The sample program does exhibit the problem on my system. I am using
> Perl build 805 rather than 810, but I downloaded Archive::Zip module
> v1.16, because the older version provided with build 805 includes a
> separate Tree module. If I zip up a sample tree using the script
> below, the freeware infozip utility shows no problem with the
> contents, but if I open the Compressed folder in Windows Explorer it
> shows zero length files alongside the folders, with the same name as
> the folders, and extraction fails. If I create the compressed folder
> using the Windows built-in compressed folder functionality, it creates
> a similar zip but without the zero length files.
>

I take it that means the problem occurs only when you mix A::Z and Windows
built-in compressed folder functionality.
I didn't even know Windows had such built-in functionality (wrt '.zip'
files), and I don't know how to access that functionality ...... so I can't
really be of much help in that regard :-)

If infozip is handling them correctly, maybe it would be simpler if you
associate the '.zip' extension with the infozip executable - and have
infozip be the default handler for zip files.

(I use WinZip, and it seems to have no problem with files created using the
A::Z module.)

Cheers,
Rob

Re: archive::zip addtree creates zero-length files

am 09.11.2005 02:59:57 von Alan Stewart

On Tue, 08 Nov 2005 21:21:52 GMT, graham@nospam.steelworks.org.uk
(Graham) wrote:

>The sample program does exhibit the problem on my system. I am using
>Perl build 805 rather than 810, but I downloaded Archive::Zip module
>v1.16, because the older version provided with build 805 includes a
>separate Tree module. If I zip up a sample tree using the script
>below, the freeware infozip utility shows no problem with the
>contents, but if I open the Compressed folder in Windows Explorer it
>shows zero length files alongside the folders, with the same name as
>the folders, and extraction fails. If I create the compressed folder
>using the Windows built-in compressed folder functionality, it creates
>a similar zip but without the zero length files.
>
>On Mon, 7 Nov 2005 10:57:30 +1100, "Sisyphus"
> wrote:
>
>>Couldn't reproduce the problem. This worked fine for me (AS perl build 810):
>>
>>use warnings;
>>use Archive::Zip;
>>$zip = Archive::Zip->new();
>>$zip->addTree( '.', '');
>>$zip->writeToFileNamed("test.zip");
>>

By default, addTree and infozip add entries for each file and and for
each directory to the zip file, while pkzip and Windows do not add
directory entries.

Perhaps Windows is having a problem with the directory entries and
trying to treat them as zero length files.

Can Windows handle a zip created by infozip with just -r ?

To prevent infozip from making dir entries, use -D:

zip -r -D some.zip my_dir/

To prevent addTree from doing it, use a filter:

$zip->addTree( $root, $dest, sub { -f } )

This came up in a PAR discussion, since PAR also didn't handle dir
entries well.

Alan Stewart

Re: archive::zip addtree creates zero-length files

am 12.11.2005 22:34:15 von Graham

On Tue, 08 Nov 2005 17:59:57 -0800, Alan Stewart
wrote:
>Can Windows handle a zip created by infozip with just -r ?
>
>To prevent infozip from making dir entries, use -D:
>
> zip -r -D some.zip my_dir/
>
>To prevent addTree from doing it, use a filter:
>
> $zip->addTree( $root, $dest, sub { -f } )
>
Thanks, Alan! That has solved my problem. I used to use a DOS batch
file with infozip to do my daily backup. I never had a problem
retrieving from the backups using Windows compressed folder
functionality, and I wasn't using a -D option. I recently rewrote the
backup procedure in Perl, to give more flexibility, but I soon
discovered that I could not extract subtrees from the backups using
Windows compressed folders. It now works great!

Graham
--
Graham Steel: graham@nospam.steelworks.org.uk
Web: http://www.steelworks.org.uk