{Daten eines MemoryStreams komprimieren}
function Compress(
var MemoryStream: TMemoryStream): double;
var
CompressionStream:
ZLib.TCompressionStream;
temp: TMemoryStream;
begin
temp := TMemoryStream.Create;
CompressionStream := TCompressionStream.Create(clmax, temp);
try
MemoryStream.Seek(0, soFromBeginning);
CompressionStream.CopyFrom(MemoryStream, MemoryStream.Size);
temp.Seek(0, soFromBeginning);
MemoryStream.Seek(0, soFromBeginning);
MemoryStream.CopyFrom(temp, temp.Size);
result := CompressionStream.compressionrate;
finally
CompressionStream.Free;
temp.Free;
end;
end;
{Daten eines MemoryStreams dekomprimieren}
procedure Decompress(
var MemoryStream: TMemoryStream);
var
DeCompressionStream:
ZLib.TDeCompressionStream;
temp: TMemoryStream;
begin
temp := TMemoryStream.Create;
DecompressionStream := TDecompressionStream.Create(temp);
try
MemoryStream.Seek(0, soFromBeginning);
DecompressionStream.CopyFrom(MemoryStream, MemoryStream.Size);
MemoryStream.Seek(0, soFromBeginning);
temp.Seek(0, soFromBeginning);
MemoryStream.CopyFrom(temp, temp.Size);
finally
DecompressionStream.Free;
temp.Free;
end;
end;