How does one read file line by line / upto a specific delimeter of an MmFile?
Adnan
relay.public.adnan at outlook.com
Mon Mar 16 13:09:08 UTC 2020
On Sunday, 15 March 2020 at 00:37:35 UTC, H. S. Teoh wrote:
> On Sat, Mar 14, 2020 at 10:37:37PM +0000, Adnan via
> Digitalmars-d-learn wrote:
>> https://dlang.org/library/std/mmfile/mm_file.html doesn't seem
>> to
>> specify anything similar to lines() or byLine() or
>> byLineCopy() etc.
>
> That's because a memory-mapped file appears directly in your
> program's memory address space as if it was an array of bytes
> (ubyte[]). No interpretation is imposed upon the contents. If
> you want lines out of it, try casting the memory to
> const(char)[] and using std.algorithm.splitter to get a range
> of lines. For example:
>
> auto mmfile = new MmFile("myfile.txt");
> auto data = cast(const(char)[]) mmfile[];
> auto lines = data.splitter("\n");
> foreach (line; lines) {
> ...
> }
>
>
> T
Would it be wasteful to cast the entire content into a const
string? Can a memory mapped file be read with a buffer?
More information about the Digitalmars-d-learn
mailing list