if (DecomStream <> nil) then
DecomStream.Free;
MessageDlg(DECOMPRESS_ERROR + #10 + E.Message, mtError, [mbOk], 0);
end;
end;
end;
// 压缩流
procedure CompressStream(InStream, OutStream: TStream);
var
i: Integer;
Buf: array[0..BufSize] of byte;
ComStream: TCompressionStream;
begin
ComStream := Nil;
try
InStream.Position := 0;
ComStream := TCompressionStream.Create(clMax, OutStream);
for i := 1 to (InStream.Size div BufSize) do begin
InStream.ReadBuffer(Buf, BufSize);
ComStream.Write(Buf, BufSize);
end;
i := InStream.Size mod BufSize;
if (i > 0) then begin
InStream.ReadBuffer(Buf, i);
ComStream.Write(Buf, i);
End;
ComStream.Free;
ComStream := nil;
// 在此写加密流代码
// EncryptStream(OutStream);
except
on E: Exception do begin
if (ComStream <> nil) then
ComStream.Free;
MessageDlg(COMPRESS_STRM_ERROR + #10 + E.Message, mtError, [mbOk], 0);
end;
end;
end;
// 解压流
procedure DecompressStream(InStream, OutStream: TStream);
var
i: Integer;
Buf: array[0..BufSize] of Byte;
DecomStream: TDecompressionStream;
begin
DecomStream := nil;
try
// 在此写解密流代码
// DecryptStream(InStream);
DecomStream := TDeCompressionStream.Create(InStream);
repeat
i := DecomStream.Read(Buf, BufSize);
OutStream.WriteBuffer(Buf, i);
until (i = 0);
OutStream.Position := 0;
DecomStream.Free;
DecomStream := nil;
except
on E: Exception do begin
if (DecomStream <> nil) then
DecomStream.Free;
MessageDlg(DECOMPRESS_STRM_ERROR + #10 + E.Message, mtError, [mbOk], 0);
end;
end;
end;
end.