TZCompressionStream使用问题。

cxxer 2022-04-05 20:35:16

 



 

 

 

 

 

void __fastcall TfrmMain::btnCompressClick(TObject *Sender)
{
	TFileStream *input = new TFileStream(Edit1->Text, fmOpenRead);
	TFileStream *output = new TFileStream(Edit2->Text + ".zip", fmCreate);
	TZCompressionStream *zip = new TZCompressionStream(output, zcDefault);

	zip->CopyFrom(input, input->Size);

	zip->Free();
	input->Free();
	output->Free();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnDecompressClick(TObject *Sender)
{
	TFileStream *input = new TFileStream(Edit1->Text, fmOpenRead);
	TFileStream *output = new TFileStream(ChangeFileExt(Edit1->Text, ""), fmCreate);
	TZDecompressionStream *unzip = new TZDecompressionStream(input);

	output->CopyFrom(unzip, 0);

	unzip->Free();
	input->Free();
	output->Free();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::Button1Click(TObject *Sender)
{
	if (OpenDialog1->Execute()) {
		Edit1->Text = OpenDialog1->FileName;
	}
}

[bcc32c Error] UnitZLibCompressDecompress.cpp(21): no matching constructor for initialization of 'System::Zlib::TZCompressionStream'
  System.ZLib.hpp(154): candidate constructor not viable: no known conversion from 'System::Classes::TFileStream *' to 'System::Zlib::TCompressionLevel' for 1st argument
  System.ZLib.hpp(152): candidate constructor not viable: requires single argument 'dest', but 2 arguments were provided
  System.ZLib.hpp(153): candidate constructor not viable: requires 3 arguments, but 2 were provided

...全文
276 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxxer 2022-04-06
  • 打赏
  • 举报
回复
```c++
class PASCALIMPLEMENTATION TZCompressionStream : public TCustomZStream
{
    typedef TCustomZStream inherited;
    
private:
    float __fastcall GetCompressionRate();
    
public:
    __fastcall TZCompressionStream(System::Classes::TStream* dest)/* overload */;
    __fastcall TZCompressionStream(System::Classes::TStream* dest, TZCompressionLevel compressionLevel, int windowBits)/* overload */;
    __fastcall TZCompressionStream(TCompressionLevel compressionLevel, System::Classes::TStream* dest)/* overload */;
    __fastcall virtual ~TZCompressionStream();
...
};
TZCompressionStream *zip = new TZCompressionStream(output,zcDefault,64);

```

  • 打赏
  • 举报
回复

TZCompressionStream的构造函数有1、2、3个参数三种重载,用两个参数的可以:
TZCompressionStream *zip = new TZCompressionStream(zcDefault, output);

ooolinux 2022-04-05
  • 打赏
  • 举报
回复

构造函数参数不对。

号称比 DELPHI 自带的 zlib 更快 ...Hello,you can found an optimized version of Zlib 1.2.1 that you can embed into every Delphi executable without use external dlls.Further I have build a little example hoping to aid "young" Delphi programmers getting in trouble with streams...Please let me know if you‘ll discover errors.These objects and sources are targeted for executing into P6+ CPU core, and Delphi5-6-7-x software.Benchmarks show this zlib 40% average faster than native DLL distribution and 100% reliable (original test of zlib 1.1.4 version).How to compress and decompress a file:procedure TForm1.Button1Click(Sender: TObject);var InputStream, OutputStream: TFileStream; DeCompressionStream: TZDecompressionStream; CompressionStream: TZCompressionStream; InputFileName, OutputFileName: string;begin//compress InputFileName := ‘c:image.png‘; OutputFilename := ‘c:image.png.bzip‘; InputStream := TFileStream.Create(InputFileName, fmOpenRead); OutputStream := TFileStream.Create(OutputFileName, fmCreate); CompressionStream := TZCompressionStream.Create(OutputStream, zcFastest); CompressionStream.CopyFrom(InputStream, InputStream.Size); CompressionStream.Free; OutputStream.Free; InputStream.Free;// decompress InputFileName := ‘c:image.png.bzip‘; OutputFilename := ‘c:image2.png‘; //rename to original into final code InputStream := TFileStream.Create(InputFileName, fmOpenRead); OutputStream := TFileStream.Create(OutputFileName, fmCreate); DecompressionStream := TZDecompressionStream.Create(InputStream); OutputStream.CopyFrom(DecompressionStream, 0); DecompressionStream.Free; OutputStream.Free; InputStream.Free;end;Cheers,Roberto Della Pasqua,www.dellapasqua.com.Btw: these sources code of zlib 1.2.1 aren‘t changed by me and now I get some compiler warnings, but don‘t worry: they are only little hints about code sintax (cross-platform C compiler typical behavior).

13,873

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧