Sample code for 30+ languages & platforms
Perl

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

my $http = Chilkat2::Http->new;

my $bd = Chilkat2::BinData->new;

# This URL is valid and can be tested...
my $success = $http->QuickGetBd('https://chilkatdownload.com/example_data/hamlet.zip', $bd);
if (!$http->LastMethodSuccess) {
    print $http->LastErrorText, "\n";
    exit;
}

my $zip = Chilkat2::Zip->new;

# Open the zip from the bytes contained in bd.
$success = $zip->OpenBd($bd);
if (!$success) {
    print $zip->LastErrorText, "\n";
    exit;
}

# Get the entry for the file we want..
my $entry = Chilkat2::ZipEntry->new;
$success = $zip->EntryOf('hamlet.xml', $entry);
if (!$success) {
    print $zip->LastErrorText, "\n";
    exit;
}

# Convert all line endings to CRLF (if needed)
my $lineEndingBehavior = 2;
my $xmlStr = $entry->UnzipToString($lineEndingBehavior, 'utf-8');
if (!$entry->LastMethodSuccess) {
    print $entry->LastErrorText, "\n";
    exit;
}

# The XML in this case is about 274K, so let's just examine the last 20 lines...
my $sb = Chilkat2::StringBuilder->new;
$sb->Append($xmlStr);

print $sb->LastNLines(20, 1), "\n";