Click here to get back home

archive::zip addtree creates zero-length files

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
archive::zip addtree creates zero-length files Graham 11-06-2005
Get Chitika Premium
Posted by Graham on November 6, 2005, 9:35 pm
Please log in for more thread options


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


Posted by Sisyphus on November 7, 2005, 10:57 am
Please log in for more thread options



> 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




Posted by Graham on November 8, 2005, 9:21 pm
Please log in for more thread options


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"

>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


Posted by Alan Stewart on November 8, 2005, 5:59 pm
Please log in for more thread options


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



Posted by Graham on November 12, 2005, 9:34 pm
Please log in for more thread options


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


Similar ThreadsPosted
LWP::UserAgent POSTing creates 2 packets - I want just 1 October 27, 2005, 2:42 pm
Portable dot-files (hidden-files) ? November 5, 2007, 1:20 am
Want to generate Excel charts inside Excel files by Perl CGI generating Excel files using WriteExcel.pm December 8, 2008, 3:46 pm
Archive::Tar August 14, 2004, 9:41 am
[ANN] Archive::Zip 1.12 released July 12, 2004, 8:21 pm
Archive::Tar on win32 September 16, 2004, 8:40 am
[ANN] Archive::Zip 1.14 released October 22, 2004, 4:04 pm
[ANN] Archive::Zip 1.14 released October 22, 2004, 11:03 pm
Archive::Zip problem July 3, 2006, 5:25 am
Using Archive::Zip extractTree(); January 2, 2007, 4:33 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap