TRawByteStringStream
TRawByteStringStream = class(TStream) protected fDataString: RawByteString; fPosition: Integer; procedure SetSize(NewSize: Longint); override; public constructor Create(const aString: RawByteString = ''); overload; function Read(var Buffer; Count: Longint): Longint; override; function Seek(Offset: Longint; Origin: Word): Longint; override; function Write(const Buffer; Count: Longint): Longint; override; property DataString: RawByteString read fDataString write fDataString; end; { TRawByteStringStream } constructor TRawByteStringStream.Create(const aString: RawByteString); begin fDataString := aString; end; function TRawByteStringStream.Read(var Buffer; Count: Integer): Longint; begin if Count <= 0 then Result := 0 else begin Result := Length(fDataString) - fPosition; if Result > Count then Result := Count; Move(PByteArray(fDataString)[fPosition], Buffer, Result); inc(fPosition, Result); end; end; function TRawByteStringStream.Seek(Offset: Integer; Origin: Word): Longint; begin case Origin of soFromBeginning: fPosition := Offset; soFromCurrent: fPosition := fPosition + Offset; soFromEnd: fPosition := Length(fDataString) - Offset; end; if fPosition > Length(fDataString) then fPosition := Length(fDataString) else if fPosition < 0 then fPosition := 0; result := fPosition; end; procedure TRawByteStringStream.SetSize(NewSize: Integer); begin SetLength(fDataString, NewSize); if fPosition > NewSize then fPosition := NewSize; end; function TRawByteStringStream.Write(const Buffer; Count: Integer): Longint; begin if Count <= 0 then Result := 0 else begin Result := Count; SetLength(fDataString, fPosition + Result); Move(Buffer, PByteArray(fDataString)[fPosition], Result); inc(FPosition, Result); end; end;