procedure TForm1.FormCreate(Sender: TObject);
begin
ZipDataStream := TMemoryStream.Create();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ZipDataStream.Free;
end;
procedure TForm1.ButtonCompressClick(Sender: TObject);
var
CompStream :
ZLib.TCompressionStream;
SourceStream : TStringStream;
SourceSize : Integer;
b : Byte;
begin
ZipDataStream.Size := 0;
SourceStream := TStringStream.Create(Memo1.Text);
SourceSize := SourceStream.Size;
CompStream :=
ZLib.TCompressionStream.Create(clDefault, ZipDataStream);
try
CompStream.CopyFrom(SourceStream, 0);
finally
CompStream.Free;
SourceStream.Free;
end;
Label1.Caption := Format('
%d Bytes komprimiert zu %d Bytes.',
[SourceSize, ZipDataStream.Size]);
ZipDataStream.Position := 0;
memo2.clear;
while ZipDataStream.
Read(b, 1) = 1
do
memo2.Text := memo2.Text + IntToHex(b,2) +'
';
end;
procedure TForm1.ButtonDecompressClick(Sender: TObject);
var
DeCompStream :
ZLib.TDeCompressionStream;
TargetStream : TStringStream;
s :
String;
c : AnsiChar;
begin
ZipDataStream.Position := 0;
TargetStream := TStringStream.Create('
');
DeCompStream :=
ZLib.TDeCompressionStream.Create(ZipDataStream);
try
s := '
';
while DeCompStream.
Read(c, SizeOf(c)) = SizeOf(c)
do
s := s + c;
Memo3.Text := s;
finally
DeCompStream.Free;
TargetStream.Free;
end;
end;