KaZip for C++Builder2009/Delphi
我已经在 C++Builder2009 上下载并安装了 KaZip2.0(有一些小的更改=>仅将类型 String 设置为 AnsiString)。我写过:
KAZip1->FileName = "test.zip";
KAZip1->CreateZip("test.zip");
KAZip1->Active = true;
KAZip1->Entries->AddFile("pack\\text.txt","xxx.txt");
KAZip1->Active = false;
KAZip1->Close();
现在他创建了一个 test.zip,其中包含 xxx.txt(59 字节原始,21 字节打包)。我在 WinRAR 中成功打开存档并想要打开 xxx.txt,但 WinRAR 说文件已损坏。 :(
出了什么问题?有人可以帮助我吗?
提取无法工作,因为文件已损坏?
KAZip1->FileName = "test.zip";
KAZip1->Active = true;
KAZip1->Entries->ExtractToFile("xxx.txt","zzz.txt");
KAZip1->Active = false;
KAZip1->Close();
I have download and install KaZip2.0 on C++Builder2009 (with little minor changes => only set type String to AnsiString). I have write:
KAZip1->FileName = "test.zip";
KAZip1->CreateZip("test.zip");
KAZip1->Active = true;
KAZip1->Entries->AddFile("pack\\text.txt","xxx.txt");
KAZip1->Active = false;
KAZip1->Close();
now he create a test.zip with included xxx.txt (59byte original, 21byte packed). I open the archiv in WinRAR successful and want open the xxx.txt, but WinRAR says file is corrupt. :(
What is wrong? Can somebody help me?
Extract not working, because file is corrupt?
KAZip1->FileName = "test.zip";
KAZip1->Active = true;
KAZip1->Entries->ExtractToFile("xxx.txt","zzz.txt");
KAZip1->Active = false;
KAZip1->Close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用 RawByteString 而不是 AnsiString。
Use RawByteString instead of AnsiString.
我不知道 KaZip2.0 是如何实现的,但一般来说,要使一个在设计时没有考虑到 Unicode 支持的 Delphi/C++ 库正常工作,您需要做两件事:
在德尔福< 2009,Char = AnsiChar,String = AnsiString,AWin32Function = AWin32FunctionA,但在Delphi >= 2009中,默认情况下,Char = WideChar,String = UnicodeString,AWin32Function = AWin32FunctionW。
I have no idea how KaZip2.0 is implemented, but in general, to make a Delphi/C++ library that was designed without Unicode support in mind working properly you need to do two things:
In Delphi < 2009, Char = AnsiChar, String = AnsiString, AWin32Function = AWin32FunctionA, but in Delphi >= 2009, by default, Char = WideChar, String = UnicodeString, AWin32Function = AWin32FunctionW.
WinRAR 可能只是无法识别标头。尝试在 Windows 或其他一些 zip 程序中打开它。
WinRAR could be simply failing to recognize the header. Try opening it in Windows or some other zip programs.
这并不总是正确的,它可能会编译,但这并不意味着它在 D2009 或 CB2009 中可以正常工作,您需要显示将字符串转换为 AnsiStrings 的位置,特别是代码处理:缓冲区、流和 I/O。
That's doesn't work always right, it may compile but it doesn't mean it will work right in D2009 or CB2009, you need to show the places that you convert Strings to AnsiStrings, specially the code deal with : Buffers, Streams and I/O.
你的代码是错误的,这并不奇怪; KaZip 没有文档。
正确的代码是:
It's not surprising that your code is wrong; KaZip has no documentation.
Proper code is: