![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Add Text Files to a ZIP Using AddStringSee more Zip ExamplesThis example demonstrates how to use the Each string is converted to bytes using the specified character encoding and stored as a separate file entry within the ZIP archive. This method is useful for dynamically generating small text files such as configuration files, reports, JSON documents, XML, or log files entirely in memory.
IncludeFile "CkZip.pb" Procedure ChilkatExample() success.i = 0 zip.i = CkZip::ckCreate() If zip.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkZip::ckNewZip(zip,"stringEntries.zip") If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Add a README text file. readmeText.s = "This ZIP archive was created using AddString." success = CkZip::ckAddString(zip,"docs/readme.txt",readmeText,"utf-8") If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Add a JSON configuration file. jsonText.s = "{ " + Chr(34) + "server" + Chr(34) + ": " + Chr(34) + "example.com" + Chr(34) + ", " + Chr(34) + "port" + Chr(34) + ": 443 }" success = CkZip::ckAddString(zip,"config/settings.json",jsonText,"utf-8") If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Add a small XML document. xmlText.s = "<root><status>OK</status></root>" success = CkZip::ckAddString(zip,"xml/status.xml",xmlText,"utf-8") If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf ; Write the ZIP archive to disk and close it. success = CkZip::ckWriteZipAndClose(zip) If success = 0 Debug CkZip::ckLastErrorText(zip) CkZip::ckDispose(zip) ProcedureReturn EndIf Debug "ZIP archive created successfully." CkZip::ckDispose(zip) ProcedureReturn EndProcedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.