StreamEx contains the class TMemoryStreamEx which encapsulates the TReader and TWriter functions of Delphi. The TReader and TWriter are very useful but you must set them up every time you want to use them.
Using the encapsulated stream you can read and write using the TReader & TWriter by starting it with a BeginReader, EndReader, BeginWriter, EndWriter block. Example:
Writing File
var fp:TMemoryStreamEx;
begin
fp:=TMemoryStreamEx.Create;
fp.BeginWriter;
fp.WriteBoolean(TRUE);
fp.WriteString('String Test');
fp.WriteFloat(1.345);
fp.EndWriter;
fp.SaveToFile('c:\test.xxx');
fp.Free;
end;
Reading File
var fp:TMemoryStreamEx;
begin
fp:=TMemoryStreamEx.Create;
fp.LoadFromFile('c:\test.xxx');
fp.position:=0;
fp.BeginReader;
if (fp.ReadBoolean) then memo1.lines.add('True');
memo1.lines.add(fp.ReadString);
memo1.lines.add(floattostr(fp.ReadFloat));
fp.EndReader;
fp.Free;
end;
The BufferSize property is set to default at 1024 bytes. This can be changed through this property. All the TReader and TWriter encapsulations are the exact as Delphi so look at Delphi's help for more information on these.
The other features this class offers are it's block operations. These allow deleting and inserting of other streams into itself. The functions are:
function CutBlock(Offset,Size:longint):TMemoryStreamEx;
CutBlock will cut the current stream at Offset and the number of Size bytes and return a new stream containing the cut data. No cutting is performed if the Offset or Size is greater than the CurrentStream.
procedure InsertBlock(Offset:longint;InsertStream:TStream);
InsertBlock will insert a stream a Offset. All data at Offset will be pushed to end of inserted block to make room.
procedure DeleteBlock(Offset,Size:longint);
DeleteBlock will remove data from stream at Offset and with Size bytes.
procedure DeleteRange(StartOfs,EndOfs:longint);
DeleteRange works much like DeleteBlock except you specify the StartOffset and EndOffset
procedure FillBlock(Offset,Size:longint; FillByte:byte);
FillBlock will fill a stream at Offset and for size with the fill byte all data is overwritten and the stream will be expanded if size is larger than currentstream.
That is all, if you have suggestions send them to the e-mail above.