Use of TZCompressionStream

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Post Reply
yunixzoo
Posts: 2
Joined: Wed Oct 21, 2020 4:37 am

Use of TZCompressionStream

Post by yunixzoo »

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.
rlebeau
BCBJ Author
BCBJ Author
Posts: 1726
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA
Contact:

Re: Use of TZCompressionStream

Post by rlebeau »

yunixzoo wrote: Thu Oct 22, 2020 6:18 am I have tried the coding sample which is described in the titled "ZLibCompressDecompress (C++)" in help as follows. But I faced compile errors.
Such as? Which errors exactly, on which lines?
yunixzoo wrote: Thu Oct 22, 2020 6:18 am 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.
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
HsiaLin
BCBJ Master
BCBJ Master
Posts: 333
Joined: Sun Jul 08, 2007 6:29 pm

Re: Use of TZCompressionStream

Post by HsiaLin »

I tried it in XE5 and it works this way. Must keep Edit1 and Edit2
texts the same format used in this source.
Attachments
TZtest.zip
TZCompressionStream test XE5
(5.28 KiB) Downloaded 42 times
Last edited by HsiaLin on Sat Oct 24, 2020 6:40 am, edited 1 time in total.
yunixzoo
Posts: 2
Joined: Wed Oct 21, 2020 4:37 am

Re: Use of TZCompressionStream

Post by yunixzoo »

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.
Attachments
sample.zip
sample with ZLib
(147.68 KiB) Downloaded 39 times
Post Reply