Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Download a Zip from a URL and OpenBd. (No .zip file is created)Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.
#include <C_CkHttpW.h> #include <C_CkBinDataW.h> #include <C_CkZipW.h> #include <C_CkZipEntryW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; HCkBinDataW bd; BOOL success; HCkZipW zip; HCkZipEntryW entry; int lineEndingBehavior; const wchar_t *xmlStr; HCkStringBuilderW sb; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); bd = CkBinDataW_Create(); // This URL is valid and can be tested... success = CkHttpW_QuickGetBd(http,L"http://chilkatdownload.com/example_data/hamlet.zip",bd); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bd); return; } zip = CkZipW_Create(); // Open the zip from the bytes contained in bd. success = CkZipW_OpenBd(zip,bd); if (success == FALSE) { wprintf(L"%s\n",CkZipW_lastErrorText(zip)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bd); CkZipW_Dispose(zip); return; } // Get the entry for the file we want.. entry = CkZipW_GetEntryByName(zip,L"hamlet.xml"); if (CkZipW_getLastMethodSuccess(zip) != TRUE) { wprintf(L"%s\n",CkZipW_lastErrorText(zip)); CkHttpW_Dispose(http); CkBinDataW_Dispose(bd); CkZipW_Dispose(zip); return; } // Convert all line endings to CRLF (if needed) lineEndingBehavior = 2; xmlStr = CkZipEntryW_unzipToString(entry,lineEndingBehavior,L"utf-8"); if (CkZipEntryW_getLastMethodSuccess(entry) != TRUE) { wprintf(L"%s\n",CkZipEntryW_lastErrorText(entry)); CkZipEntryW_Dispose(entry); CkHttpW_Dispose(http); CkBinDataW_Dispose(bd); CkZipW_Dispose(zip); return; } // The XML in this case is about 274K, so let's just examine the last 20 lines... sb = CkStringBuilderW_Create(); CkStringBuilderW_Append(sb,xmlStr); wprintf(L"%s\n",CkStringBuilderW_lastNLines(sb,20,TRUE)); CkZipEntryW_Dispose(entry); CkHttpW_Dispose(http); CkBinDataW_Dispose(bd); CkZipW_Dispose(zip); CkStringBuilderW_Dispose(sb); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.