Lianja Requires Chilkat v11.0.0+
Lianja
Compress Large Binary File in Blocks
See more Compression Examples
Compresses a large binary file in blocks.Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loFacSrc = createobject("CkFileAccess")
loFacDest = createobject("CkFileAccess")
// Open a large binary file for reading.
llSuccess = loFacSrc.OpenForRead("qa_data/bmp/big.bmp")
if (llSuccess = .F.) then
? loFacSrc.LastErrorText
release loFacSrc
release loFacDest
return
endif
// If we compress in 64K chunks, find out how many blocks there will be.
lnBlockSize = 65536
lnNumBlocks = loFacSrc.GetNumBlocks(lnBlockSize)
// Open an output file for the compressed data.
llSuccess = loFacDest.OpenForWrite("c:/temp/qa_output/compressedBmp.dat")
if (llSuccess = .F.) then
? loFacDest.LastErrorText
release loFacSrc
release loFacDest
return
endif
loCompress = createobject("CkCompression")
loCompress.Algorithm = "deflate"
// Assuming numBlocks > 1
loCompress.FirstChunk = .T.
loCompress.LastChunk = .F.
i = 0
do while i < lnNumBlocks
loFileBytes = loFacSrc.ReadBlock(i,lnBlockSize)
loCompressedBytes = loCompress.CompressBytes(loFileBytes)
loFacDest.FileWrite(loCompressedBytes)
i = i + 1
loCompress.FirstChunk = .F.
if (i = (lnNumBlocks - 1)) then
loCompress.LastChunk = .T.
endif
enddo
loFacSrc.FileClose()
loFacDest.FileClose()
? "Finished compressing file."
release loFacSrc
release loFacDest
release loCompress