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

Do any zip libraries exist that can zip the contents of a variable, not just a file? I have a function that outputs the contents of a variable that has pre-formatted data in it like so:
print <<"CSV"; Content-Type: application/dat; charset=us-ascii Content-Disposition: attachment; filename="$fileName"\n $csvFile CSV }
Works great, but I'd like to zip the 'file' before I send it to the user. I guess I could dump the contents of the variable to a temp file, zip the temp file, then send the whole file to the user, but it seems inefficent.

Is it possible to zip the contents of the variable and output a zipped variable to the user pretending to be a zip file?
Thanks!
Answer and more detail found here

Replies are listed 'Best First'.
Re: Zip a variable?
by svenXY (Deacon) on Jan 13, 2006 at 10:51 UTC
    Hi,
    I found this:
    Zip contents in a scalar ^ Q: I want to read a Zip file from (or write one to) a scalar variable +instead of a file. How can I do this? A: Use IO::Scalar and the readFromFileHandle() and writeToFileHandle() + methods. See examples/readScalar.pl and examples/writeScalar.pl.
    in the documentation for Archive::Zip
    Is this what you are after?
    Regards,
    svenXY
      Yes, and much appreciated. I tried to search the help forums for the wrong wording, found it, then tried to reap this request. Thanks!
Re: Zip a variable?
by CountOrlok (Friar) on Jan 13, 2006 at 15:21 UTC
    Archive::Zip has a method named AddString that would do what you want.

    -imran