Handling Files with Non-ASCII Characters in ZIP Component
When creating ZIP archives that include filenames with non-ASCII characters, proper encoding must be configured to ensure filenames are preserved correctly across different platforms and languages. The Zip component supports this through either the Encoding or CodePage configuration option depending on the development environment.
Setting the Encoding Configuration Option
To ensure filenames containing non-ASCII characters are encoded correctly, set the Encoding configuration option to UTF-8 when working with .NET, Java, Android, and Xamarin.
Zip zip = new Zip();
zip.Config("Encoding=UTF-8");
zip.ArchiveFile("C:\Test\Non_ASCII_Chars.zip");
zip.IncludeFiles("C:\Test\äöüß.txt");
zip.Compress();
Setting the CodePage Configuration Option
For C++, C++ Builder, Node.js, Delphi, PHP, and ActiveX/COM, use the CodePage configuration option instead. Set it to 65001 for UTF-8 (or 4 for macOS).
var zip = new ipworkszip.zip();
zip.config("CodePage=65001");
zip.setArchiveFile("C:\Test\Non_ASCII_Chars.zip");
zip.includeFiles("C:\Test\äöüß.txt");
zip.compress();
In C++, use the wide-character version of the component (ZipW) and pass wide strings when working with non-ASCII filenames.
ZipW zipw;
zipw.Config(L"CodePage=65001");
zipw.SetArchiveFile(L"C:\Test\Non_ASCII_Chars.zip");
zipw.IncludeFiles(L"C:\Test\äöüß.txt");
zipw.Compress();
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.