(Ruby) Compress Bytes
Demonstrates how to compress binary data.
require '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() != true)
print fac.lastErrorText() + "\n";
exit
end
compress = Chilkat::CkCompression.new()
compress.put_Algorithm("deflate")
compressedBytes = Chilkat::CkByteData.new()
success = compress.CompressBytes(fileBytes,compressedBytes)
if (compress.get_LastMethodSuccess() != true)
print compress.lastErrorText() + "\n";
exit
end
success = fac.WriteEntireFile("qa_output/compressedBmp.dat",compressedBytes)
if (fac.get_LastMethodSuccess() != true)
print fac.lastErrorText() + "\n";
exit
end
|