我正在使用 Delphi 11 Community Edition,我遇到了 zlib 主要是 TZDecompressionStream 的问题,并显示消息“无效的 zstream 操作” 替你谢谢
无法使用 TZCompressionStream 解压缩压缩文件
class function TCompression.Compression(InStream:TStream; out OutStream:TStream; out Message_:string):Boolean;
var LZip: TZCompressionStream;
begin
Result:=False;
Message_:='';
try
OutStream:=TMemoryStream.Create;
InStream.Position:=0;
LZip := TZCompressionStream.Create(clDefault, OutStream);
LZip.CopyFrom(InStream, InStream.Size);
LZip.Free;
Result:=True;
except
on E:Exception do
Message_:=E.Message;
end;
end;
class function TCompression.Decompression(InStream:TStream; out OutStream:TStream; out Message_:string):Boolean;
var LZip: TZDecompressionStream;
begin
Result:=False;
Message_:='';
try
OutStream:=TMemoryStream.Create;
InStream.Position:=0;
LZip := TZDecompressionStream.Create(OutStream);
LZip.CopyFrom(InStream, InStream.Size);
LZip.Free;
Result:=True;
except
on E:Exception do
Message_:=E.Message;
end;
end;
和:
var In_, Out_, t:TStream;
msg:string;
begin
in_:=TFileStream.Create('test_encryption.dproj', fmOpenRead);
if not TCompression.Compression(In_, Out_, msg) then
raise Exception.Create(msg);
if not TCompression.Decompression(Out_, t, msg) then // <==== Line of problem
raise Exception.Create(msg);
WriteLn(t.Size);
in_.Free;
Out_.Free;
t.Free;
end.