Xbase++ Requires Chilkat v11.0.0+
Xbase++
Get Compressed ZIP Entry Data as Base64 Using ZipEntry.CopyToBase64
See more Zip Examples
This example creates a small ZIP archive containing a text file added from memory, writes the ZIP to disk, re-opens it, and then uses ZipEntry.CopyToBase64 to retrieve the compressed data for the text file as a Base64-encoded string.
The Base64 string returned by CopyToBase64 represents the compressed bytes stored for the entry inside the ZIP archive. It is not the original uncompressed text data.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oZip
LOCAL oZip2
LOCAL oEntry
LOCAL cB64
nSuccess := 0
// ------------------------------------------------------------
// First create a sample ZIP archive containing a small text file.
oZip := CreateObject("Chilkat.Zip")
nSuccess := oZip:NewZip("c:/temp/sampleText.zip")
IF (nSuccess == 0)
? oZip:LastErrorText
oZip:destroy()
RETURN
ENDIF
// Add a small text file from memory.
// The text is stored in the ZIP as "hello.txt".
nSuccess := oZip:AddString("hello.txt", "Hello from a ZIP entry!", "utf-8")
IF (nSuccess == 0)
? oZip:LastErrorText
oZip:destroy()
RETURN
ENDIF
// Write the ZIP archive to disk and close it.
nSuccess := oZip:WriteZipAndClose()
IF (nSuccess == 0)
? oZip:LastErrorText
oZip:destroy()
RETURN
ENDIF
// ------------------------------------------------------------
// Now open the ZIP archive we just created.
oZip2 := CreateObject("Chilkat.Zip")
nSuccess := oZip2:OpenZip("c:/temp/sampleText.zip")
IF (nSuccess == 0)
? oZip2:LastErrorText
oZip:destroy()
oZip2:destroy()
RETURN
ENDIF
// Get the text file entry.
oEntry := CreateObject("Chilkat.ZipEntry")
nSuccess := oZip2:EntryOf("hello.txt", oEntry)
IF (nSuccess == 0)
? "Entry not found."
oZip:destroy()
oZip2:destroy()
oEntry:destroy()
RETURN
ENDIF
// Get the compressed ZIP entry data as Base64.
//
// This is the compressed data stored inside the ZIP file,
// not the uncompressed text "Hello from a ZIP entry!".
cB64 := oEntry:CopyToBase64()
? "Base64 compressed ZIP entry data:"
? cB64
oZip2:CloseZip()
? "Done."
oZip:destroy()
oZip2:destroy()
oEntry:destroy()