我需要将 IdCompressZlib 组件与 CBuilderXE 一起使用,但我没有找到关于该主题的文档或示例。我也做了一些尝试使用它失败了。
有人可以向我发布一些关于如何使用 thsi 组件或对此类主题有用的点赞的示例吗?
更新:下面是我尝试过的示例代码,当调用 InflateStream 方法时给出错误 -5:
int err;
String Fun = "[TestCompress] ", s1, zipString, strTest = "The 'zlib' compression library provides in-memory compression \
and decompression functions, including integrity checks of the uncompressed data. \
This version of the library supports only one compression method (deflation) \
but other algorithms will be added later and will have the same stream interface. ";
TStringStream * inpStream = NULL, *outStream = NULL;
TMemoryStream * stream1 = NULL, *stream2 = NULL;
stream1 = new TMemoryStream();
stream2 = new TMemoryStream();
inpStream = new TStringStream();
outStream = new TStringStream();
inpStream->Clear();
inpStream->WriteString(strTest);
stream1->LoadFromStream(inpStream);
stream1->Position = 0;
IdCompressorZLib1->InflateStream(stream1, stream2);
outStream->Clear();
stream2->SaveToStream(outStream);
zipString = outStream->DataString;
MyLog(Fun + Format("Compress test: Compress size from [%d] to [%d]",
ARRAYOFCONST((strTest.Length(), zipString.Length()))));