in reply to Build 1 zip from file and string with IO::Compress::Zip

The documentation for IO::Compress::Zip marks Append with the Functional Interface as TODO. I tried your example using the OO interface with Append (the doc implies that should work) but got no further. However Multi-Stream seems to work:
#!/usr/bin/perl use strict; use warnings; use IO::Compress::Zip qw(zip $ZipError :constants); my $z; $z = new IO::Compress::Zip './k.zip', name => 'from_filename.t', AutoClose => 1, BinModeIn => 1 or die "IO::Compress::Zip(1) failed: $ZipError\n"; open (my $fh, '<', './a.txt') or die "Unable to open a.txt: $!"; while (<$fh>) { $z->print ($_) } close $fh; my $string = ss(); $z->newStream( Name => 'from_ram.t', ExtAttr => 0666 << 16) or die "newStream failed: $ZipError\n"; $z->print ($string); close $z; sub ss { return <<END; a b c END }
Note that I set the permissions in ExtAttr - the default does not appear to be implemented (I got 000 without it), and it is not a string as your code supplies it.

Replies are listed 'Best First'.
Re^2: Build 1 zip from file and string with IO::Compress::Zip
by mattk1 (Acolyte) on Mar 29, 2010 at 20:00 UTC
    That's exact what I wanted. Thank you. Curious. A module marked with to do's and not working implementations in core. Hope with Perl 6 comes something better. (-:
      I'm gutted :-)

      Have you tried the sample code posted that used newStream? If it doesn't work, please get back to me.

      Paul

Re^2: Build 1 zip from file and string with IO::Compress::Zip
by pmqs (Friar) on Mar 31, 2010 at 19:23 UTC
    The Append option isn't what is needed here (the way Append is used in the posted code will result in two zip files concatenated together)

    As you've demonstrated, the MultiStream option is the way to create a single zip file with multiple members.

    Regarding ExtAttr, as you say it is a number, not a string. Plus it isn't being set to "0666<<16" by default as the documentation states -- I will look into that.

    Paul