Wouldn't it be better to implement it directly as *IOUtils.TFile* (like Deplhi)?
*class function ReadAllBytes(const Path: string): TBytes; static;class function ReadAllLines(const Path: string): TStringDynArray;overload; static;class function ReadAllLines(const Path: string; const Encoding: TEncoding): TStringDynArray; overload; static;class function ReadAllText(const Path: string): string; overload; inline; static;class function ReadAllText(const Path: string; const Encoding: TEncoding): string; overload; inline; static;* Souce: http://docwiki.embarcadero.com/Libraries/Sydney/en/System.IOUtils.TFile_Methods Then there would be only one way in the RTL for this task and not two once *IOUtils* (foundation webpage says it's planned anyway) is implemented. Am Di., 6. Okt. 2020 um 10:12 Uhr schrieb Michael Van Canneyt via fpc-pascal <fpc-pascal@lists.freepascal.org>: > > > On Mon, 5 Oct 2020, Ryan Joseph via fpc-pascal wrote: > > > > > > >> On Oct 5, 2020, at 5:08 PM, Jean SUZINEAU via fpc-pascal < > fpc-pascal@lists.freepascal.org> wrote: > >> > >> In my own code I use BlockRead/BlockWrite, but I'm wondering if I've > not seen this somewhere in RTL. > >> > >> > > > > This looks good to me what about the concerns raised by Michael? I don't > > know enough about text formats but using AnsiString always just seems to > > work for me (I assume the compiler did something magic behind the > scenes). > > No, we don't deal in magic, only bits and bytes :-) > > I added the following functions to the sysutils unit (rev 47056): > > // Read raw content as bytes > > Function GetFileContents(Const aFileName : RawByteString) : TBytes; > Function GetFileContents(Const aFileName : UnicodeString) : TBytes; > Function GetFileContents(Const aHandle : THandle) : TBytes; > > // Read content as string > > // Assume TEncoding.SystemEncoding > Function GetFileAsString(Const aFileName : RawByteString) : RawByteString; > // Specify encoding > Function GetFileAsString(Const aFileName : RawByteString; aEncoding : > TEncoding) : RawByteString; > // Assume TEncoding.Unicode contents > Function GetFileAsString(Const aFileName : UnicodeString) : UnicodeString; > // Specify encoding, return Unicode string. > Function GetFileAsString(Const aFileName : UnicodeString; aEncoding : > TEncoding) : UnicodeString; > > These functions will raise an exception if the file cannot be opened or > read. > They cannot be used on handles that do not support FileSeek() (sockets, > pipes, stdin/stdout etc.). > > I did some tests on encoding conversion but not extensively. > If you find any errors, please report them through the bugtracker. > > Michael. > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal