(Perl) Compress Bytes
Demonstrates how to compress binary data.
use chilkat();
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$fac = chilkat::CkFileAccess->new();
$fileBytes = chilkat::CkByteData->new();
$success = $fac->ReadEntireFile("qa_data/bmp/big.bmp",$fileBytes);
if ($fac->get_LastMethodSuccess() != 1) {
print $fac->lastErrorText() . "\r\n";
exit;
}
$compress = chilkat::CkCompression->new();
$compress->put_Algorithm("deflate");
$compressedBytes = chilkat::CkByteData->new();
$success = $compress->CompressBytes($fileBytes,$compressedBytes);
if ($compress->get_LastMethodSuccess() != 1) {
print $compress->lastErrorText() . "\r\n";
exit;
}
$success = $fac->WriteEntireFile("qa_output/compressedBmp.dat",$compressedBytes);
if ($fac->get_LastMethodSuccess() != 1) {
print $fac->lastErrorText() . "\r\n";
exit;
}
|