I am cheking the function of Compression with TZCompressionStream. I have tried the coding sample which is described in the titled "ZLibCompressDecompress (C++)" in help as follows. But I faced compile errors.
/* Create the Input, Output and Compressed streams. */
TFileStream *input = new TFileStream(Edit1->Text, fmOpenRead);
TFileStream *output = new TFileStream(Edit2->Text + ".zip", fmCreate);
TZCompressionStream *zip = new TZCompressionStream(output, zcDefault);
/* Compress data. */
zip->CopyFrom(input, input->Size);
/* Free the streams. */
zip->Free();
input->Free();
output->Free();
Then I tried several times with modifying some of the above list because I noticed the parameter "zcDefault" above might not be correct by considering and refering some coding samples in the internet.
/* Create the Input, Output and Compressed streams. */
TFileStream *input = new TFileStream(Edit1->Text, fmOpenRead);
TFileStream *output = new TFileStream(Edit2->Text + ".zip", fmCreate);
TZCompressionStream *zip = new TZCompressionStream(output, TCompressionLevel::clDefault);
/* Compress data. */
zip->CopyFrom(input, input->Size);
/* Free the streams. */
delete zip;
delete input;
delete output;
I appreciated if you could show me how to compress and decompress with TZCompressionStream.
Thank you.
Use of TZCompressionStream
Moderator: 2ffat
Re: Use of TZCompressionStream
Such as? Which errors exactly, on which lines?
zcDefault is used with the ZCompress(), ZCompressStr(), and ZCompressStream() functions, not with the TZCompressionStream class. You are correct that you need to use TCompressionLevel::clDefault instead.
Remy Lebeau (TeamB)
Lebeau Software
Lebeau Software
Re: Use of TZCompressionStream
I tried it in XE5 and it works this way. Must keep Edit1 and Edit2
texts the same format used in this source.
texts the same format used in this source.
- Attachments
-
- TZtest.zip
- TZCompressionStream test XE5
- (5.28 KiB) Downloaded 100 times
Last edited by HsiaLin on Sat Oct 24, 2020 6:40 am, edited 1 time in total.
Re: Use of TZCompressionStream
I have tried the sample sent by HsiaLin-san, it works fine! No problem at all.
Thanks to rlebeau-san and HsiaLin-san, I have understood how to compress data files with ZLib and that I can do that by 2 ways, as follows.
TFileStream *input = new TFileStream(L"abc.txt", fmOpenRead);
TFileStream *output = new TFileStream(L"abc.zip", fmCreate);
(1) Method 1: CopyFrom()
TZCompressionStream *zip = new TZCompressionStream(TCompressionLevel::clDefault, output);
zip->CopyFrom(input, input->Size);
(2) Method 2: ZCompressStream
ZCompressStream(input, output, zcDefault);
Thank you very much.
The reason why I cound not compress data files with ZLib correctly, is that I refered the sample list described in Help in IDE (the last one in sample codes)
So, I hope the sample list will be amended in near future to avoid confusion.
Thanks to rlebeau-san and HsiaLin-san, I have understood how to compress data files with ZLib and that I can do that by 2 ways, as follows.
TFileStream *input = new TFileStream(L"abc.txt", fmOpenRead);
TFileStream *output = new TFileStream(L"abc.zip", fmCreate);
(1) Method 1: CopyFrom()
TZCompressionStream *zip = new TZCompressionStream(TCompressionLevel::clDefault, output);
zip->CopyFrom(input, input->Size);
(2) Method 2: ZCompressStream
ZCompressStream(input, output, zcDefault);
Thank you very much.
The reason why I cound not compress data files with ZLib correctly, is that I refered the sample list described in Help in IDE (the last one in sample codes)
So, I hope the sample list will be amended in near future to avoid confusion.
- Attachments
-
- sample.zip
- sample with ZLib
- (147.68 KiB) Downloaded 91 times