Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
loBd = createobject("CkBinData")
// This URL is valid and can be tested...
llSuccess = loHttp.QuickGetBd("https://chilkatdownload.com/example_data/hamlet.zip",loBd)
if (loHttp.LastMethodSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loBd
return
endif
loZip = createobject("CkZip")
// Open the zip from the bytes contained in bd.
llSuccess = loZip.OpenBd(loBd)
if (llSuccess = .F.) then
? loZip.LastErrorText
release loHttp
release loBd
release loZip
return
endif
// Get the entry for the file we want..
loEntry = createobject("CkZipEntry")
llSuccess = loZip.EntryOf("hamlet.xml",loEntry)
if (llSuccess = .F.) then
? loZip.LastErrorText
release loHttp
release loBd
release loZip
release loEntry
return
endif
// Convert all line endings to CRLF (if needed)
lnLineEndingBehavior = 2
lcXmlStr = loEntry.UnzipToString(lnLineEndingBehavior,"utf-8")
if (loEntry.LastMethodSuccess = .F.) then
? loEntry.LastErrorText
release loHttp
release loBd
release loZip
release loEntry
return
endif
// The XML in this case is about 274K, so let's just examine the last 20 lines...
loSb = createobject("CkStringBuilder")
loSb.Append(lcXmlStr)
? loSb.LastNLines(20,.T.)
release loHttp
release loBd
release loZip
release loEntry
release loSb