Dafür nimmt man eigentlich
TStreamReader
und
TStreamWriter
.
Stream und Encoding angeben, und dann per ReadBlock/Write die Daten von links nach rechts schieben.
Und das ganze mit einer Handvoll Code:
Delphi-Quellcode:
procedure Transfer(ASource: TStream; ASourceEncoding: TEncoding; ADest: TStream; ADestEncoding: TEncoding);
const
bufferSize = 2048;
var
reader: TStreamReader;
writer: TStreamWriter;
buffer: TCharArray;
readCount: Integer;
begin
reader := TStreamReader.Create(ASource, ASourceEncoding);
try
writer := TStreamWriter.Create(ADest, ADestEncoding);
try
SetLength(buffer, bufferSize);
repeat
readCount := reader.ReadBlock(buffer, 0, bufferSize);
if readCount > 0 then
writer.Write(buffer, 0, readCount);
until (readCount < bufferSize);
finally
FreeAndNil(writer);
end;
finally
FreeAndNil(reader);
end;
end;