I/O extensions for common tasks

Basile B. b2.temp at gmx.com
Mon Dec 10 02:06:26 UTC 2018


On Monday, 10 December 2018 at 01:51:56 UTC, Andrew Pennebaker 
wrote:
> The stdlib has all the low-level components we need to do lots 
> of different workflows. However, there are a few gaps in the 
> API in terms of high level, common tasks. For example, the API 
> can read an entire Unicode text file to a string for a given 
> filename, but not for a given File object!
>
> For now, I am accomplishing this with:
>
> // Convenience function for reading an entire UTF-8 file.
> string readUTF8(File f) {
>     string s;
>
>     foreach(ubyte[] buf; f.byChunk(1024)) {
>         s ~= buf;
>     }
>
>     return s;
> }
>

There's more simple:


     auto wholeFile = f.rawRead(new char[](f.size));


Note that this kind of question should rather go there: 
https://forum.dlang.org/group/learn




More information about the Digitalmars-d mailing list