Compressing any data stream on the fly: Example
The following example compresses the data from the Notes field of Table1 to the Remarks field of Table2 and then decompresses it back.
procedure TForm1.Button1Click(Sender: TObject);
var
Stream1, Stream2 : TBlobStream;
ECLStream: TECLStream;
begin
Stream1 := TBlobStream.Create(Table1Notes, bmRead);
try
Table2.Edit;
Stream2 := Table2.CreateBlobStream(Table2.FieldByName('Remarks'), bmReadWrite);
ECLStream := TECLStream.Create(Stream2, true, '', bzipFastest);
try
ECLStream.LoadFromStream(Stream1);
Table2.Post;
finally
ECLStream.Free;
Stream2.Free;
end;
finally
Stream1.Free;
end;
Stream1 := TBlobStream.Create(Table2.FieldByName('Remarks'), bmRead);
ECLStream := TECLStream.Create(Stream1);
try
Table1.Edit;
Stream2 := Table1.CreateBlobStream(Table1Notes, bmReadWrite);
try
Stream2.CopyFrom(ECLStream, ECLStream.Size);
Table1.Post;
finally
Stream2.Free;
end;
finally
ECLStream.Free;
Stream1.Free;
end;
end;
|