Archived Forum Post

Index of archived forum posts

Question:

Perl CkByteData and CkZip

Sep 09 '16 at 13:25

I'm trying to generate a zip file entirely in memory, but I am struggling with understanding how to interface CkByteData. Perl makes us lazy, so we don't think much about data types.

Can someone offer feedback on what I'm doing wrong in this example:

#!/usr/bin/perl

use chilkat;

my $zip = new chilkat::CkZip();
$zip->UnlockComponent("XXXXXXXXX");

my $dataobj = new chilkat::CkByteData();
$dataobj->appendStr("TEST ZIP TEXT");

my $success = $zip->NewZip("test.txt.zip");
if ($success != 1) { print $zip->lastErrorText()."\n"; exit; }

my $success = $zip->AppendData("test.txt",$dataobj);
if ($success != 1) { print $zip->lastErrorText()."\n"; exit; }

my $zipdataobj = new chilkat::CkByteData();
my $success = $zip->WriteToMemory($zipdataobj);
if ($success != 1) { print $zip->lastErrorText()."\n"; exit; }

open(FILE,">test.zip");
print FILE $zipdataobj->getData();
close(FILE);


Answer

Don't forget that AppendData returns a CkZipEntry object, not a success/failure indicator.

Otherwise you pretty much have it. I would wonder if you're opening the output file in binary or text mode. Given that I work in many different programmming languages, it's something I always would question, would never remember, and would always have to lookup..

Here's an example I wrote just now that will get linked from the refdocs and example-code.com shortly..

Android: Create a Zip Entirely in Memory

Classic ASP: Create a Zip Entirely in Memory

C: Create a Zip Entirely in Memory

C++: Create a Zip Entirely in Memory

C#: Create a Zip Entirely in Memory

C# UWP/WinRT: Create a Zip Entirely in Memory

DataFlex: Create a Zip Entirely in Memory

Delphi ActiveX: Create a Zip Entirely in Memory

Delphi DLL: Create a Zip Entirely in Memory

.NET Core C#: Create a Zip Entirely in Memory

Visual FoxPro: Create a Zip Entirely in Memory

Java: Create a Zip Entirely in Memory

Lianja: Create a Zip Entirely in Memory

MFC: Create a Zip Entirely in Memory

Mono C#: Create a Zip Entirely in Memory

Node.js: Create a Zip Entirely in Memory

Objective-C: Create a Zip Entirely in Memory

Perl: Create a Zip Entirely in Memory

PHP ActiveX: Create a Zip Entirely in Memory

PHP Extension: Create a Zip Entirely in Memory

PowerBuilder: Create a Zip Entirely in Memory

PowerShell: Create a Zip Entirely in Memory

Python: Create a Zip Entirely in Memory

Ruby: Create a Zip Entirely in Memory

SQL Server: Create a Zip Entirely in Memory

Swift: Create a Zip Entirely in Memory

Tcl: Create a Zip Entirely in Memory

Unicode C: Create a Zip Entirely in Memory

Unicode C++: Create a Zip Entirely in Memory

Visual Basic 6.0: Create a Zip Entirely in Memory

VB.NET: Create a Zip Entirely in Memory

VB.NET UWP/WinRT: Create a Zip Entirely in Memory

VBScript: Create a Zip Entirely in Memory

Xojo Plugin: Create a Zip Entirely in Memory


Answer

Awesome! Thank you for those examples!