Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oBd
LOCAL oZip
LOCAL oEntry
LOCAL nLineEndingBehavior
LOCAL cXmlStr
LOCAL oSb
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oBd := CreateObject("Chilkat.BinData")
// This URL is valid and can be tested...
nSuccess := oHttp:QuickGetBd("https://chilkatdownload.com/example_data/hamlet.zip", oBd)
IF (oHttp:LastMethodSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oBd:destroy()
RETURN
ENDIF
oZip := CreateObject("Chilkat.Zip")
// Open the zip from the bytes contained in bd.
nSuccess := oZip:OpenBd(oBd)
IF (nSuccess == 0)
? oZip:LastErrorText
oHttp:destroy()
oBd:destroy()
oZip:destroy()
RETURN
ENDIF
// Get the entry for the file we want..
oEntry := CreateObject("Chilkat.ZipEntry")
nSuccess := oZip:EntryOf("hamlet.xml", oEntry)
IF (nSuccess == 0)
? oZip:LastErrorText
oHttp:destroy()
oBd:destroy()
oZip:destroy()
oEntry:destroy()
RETURN
ENDIF
// Convert all line endings to CRLF (if needed)
nLineEndingBehavior := 2
cXmlStr := oEntry:UnzipToString(nLineEndingBehavior, "utf-8")
IF (oEntry:LastMethodSuccess == 0)
? oEntry:LastErrorText
oHttp:destroy()
oBd:destroy()
oZip:destroy()
oEntry:destroy()
RETURN
ENDIF
// The XML in this case is about 274K, so let's just examine the last 20 lines...
oSb := CreateObject("Chilkat.StringBuilder")
oSb:Append(cXmlStr)
? oSb:LastNLines(20, 1)
oHttp:destroy()
oBd:destroy()
oZip:destroy()
oEntry:destroy()
oSb:destroy()