Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archive::Zip - create a new file with a specific name ?

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

reading all the man pages from CPAN,still unable to create a new zip file with my specified name:

my $zip = Archive::Zip->new();
$zip->addMember("PrinergyUpdates.txt");

I want to create and add files to a zip file where I can specify it's name.
Appreciate any advice.

Thanks


Long live king Moshiach !
 
OK,

Figured out now:
my $zip = Archive::Zip->new();
$zip->addFile("PrinergyUpdates.txt");
$zip->writeToFileNamed($NAME1);

However - If I'm zipping huge (20GB) database files into the zip - how and when should I write (writeToFileNamed) this zip file?I beleive Windows will not be able to keep this huge info in the memory...
Thanks


Long live king Moshiach !
 
You might need to write it as a filehandle.

Code:
my $fh = IO::File->new ("out.zip","w");
$zip->writeToFileHandle ($fh);
 
Thanks,

but what would be the syntax ?Shoule it be like :
my $fh = IO::File->new ("out.zip","w");
$zip->writeToFileHandle ($fh);
$zip->addFileOrDirectory($NAME);
$zip->writeToFileHandle ($fh);
$zip->addFileOrDirectory($NAME1);
$zip->writeToFileHandle ($fh);
$zip->addFileOrDirectory($NAME2);
$zip->writeToFileHandle ($fh);

?

Long live king Moshiach !
 
I'd think it would be more like:

Code:
$zip->addFileOrDirectory ($NAME);
$zip->addFileOrDirectory ($NAME1);
$zip->addFileOrDirectory ($NAME2);

my $fh = IO::File->new ("out.zip","w");
$zip->writeToFileHandle ($fh);

I think that writeToFileHandle will "stream" the data in, rather than send it all in at once (which would require the data to be in temporary memory to be written), much like while(<HANDLE>) loops read a filehandle one line at a time.

That being said, I don't know how memory efficient it is to have the whole zip object in memory to begin with. But give that a try and see if it helps.
 
Thanks,

But that's the point,I'm gonna read files of more then 1GB at once,so I've gotta make sure they are zipped instantly into a physical file.
How DO I make sure it happens ?

Long live king Moshiach !
 
Are you having individual zip files for every ~20GB database file, or zipping a bunch of different 20GB database files into one zip?
 
I don't know if Archive::Zip can do that then. I just skimmed some parts of its documentation, and it seems that it doesn't store files in memory until the file is written. I would assume that writeToFileHandle would be something to ease up on memory consumption, but it isn't very clear on that, so I'm thinking that it would have to load each database file into memory one at a time to write it to the filehandle, so there would be about 2~3GB of memory usage at any one time.

Did you try the code I posted to write the zip to a filehandle? How did that go? Did it devour all the computer's memory and then some?

If so, I guess I'd contact the module's author if I were you.
 
Thanks,

1.tried your code - get errors that I yet did not find the reason for:

error zipping KDI-PGY2500_SysInfo.nfo !!! Bad file descriptor at script/rehost.pl line 2155.
error zipping OS_PRINTERS !!! Bad file descriptor at script/rehost.pl line 2155.

2.Actualy I need Archive::Zip to work similary to the way a normal zip works- pushing things into the file one by one ...

Long live king Moshiach !
 
If WinZip has a command-line tool like GZip, you could call a system command to run that.
 
I did use zip till now,but now was asked to use Archive::Zip instead,in order not to be dependent on zip command line syntax ...

Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top