Reputation: 774
I have a code as following:
my $file = 'myFile.txt';
my $zip = Archive::Zip->new();
my $compressed = $zip->addFile($file, "newFilename");
if ($zip->writeToFileNamed('dir/test.zip') != AZ_OK)
{
print "ERROR";
}
else
{
print "DONE";
}
Pretty much easy!
The question is: is it possible to rewrite $file = 'myFile.txt'
to put there a string, which contains some data (i.e.: "123455677889") and this data must be associated with some filename (say: "myFile.txt") which does NOT exist on the server. The other words:
$data = "12344566789abcselkjlkj";
Every help is appreciated! Thank you!
Upvotes: 2
Views: 389
Reputation: 21666
addString
does exactly what you want.
# Create a file in the archive from a string.
my $string_member = $zip->addString('12344566789abcselkjlkj', 'myFile.txt');
$string_member->desiredCompressionMethod(COMPRESSION_DEFLATED);
Upvotes: 2