On 10/22/2016 06:56 PM, Eric de Hont wrote: > Op 21-10-16 om 14:13 schreef Vincent Lequertier: >> This code creates a zip file which contains several files, all named >> 'test'. The thing I'm trying to achieve is to have all the output of >> commands being appended to a 'test' file, into the zip. >> >> How can I do this properly ? I mean without having to create a temp file >> with a filehandle with all the output and adding the file to the zip >> after the for loop. > A zip-file is no compressed filesystem, so I think there is no way to do > what you want properly. > > You could do something like this, but in the else block you will have > all of your data temporarily uncompressed in memory: > > if (! $zip->memberNamed( 'test' )) { > $zip->addString($config, 'test', COMPRESSION_DEFLATED); > } > else { > $zip->contents( 'test', $zip->contents( 'test' ) . $config ); > } > > If it's too much data to fit in memory you have to go with the temp file > option. > > Just a thought though: perhaps a zip archive to compress just one file > is a bit overkill. > > Maybe IO::Compress::Gzip, which let's you compress strings in this way: > > gzip \$input \$output > > is better suited, or could at least be used in stead of the temp file. > > Greetings, > Eric de Hont
Your approach works well, thanks. I'm ziping a lot of files by the way (but I have only one file that needs to be a concatenation of multiple strings in the loop). I've just shown this tiny example to highlight what the problem was. Thank you again -- Vincent Lequertier skysymbol.github.io -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/