1 module nxt.mmfile_ex;
2 
3 /** Read-Only Lines of Contents of file $(D path).
4     TODO Use new std.string.splitLines() (via Phobos pull 2982).
5    */
6 auto mmFileLinesRO(ElementType = char)(string path)
7     if
8     (ElementType.sizeof == 1)
9 {
10     version(linux)
11     {
12         import core.sys.posix.sys.shm: __getpagesize;
13         const pageSize = __getpagesize();
14     }
15     else
16     {
17         const pageSize = 4096;
18     }
19     import std.mmfile: MmFile;
20     import std.path: expandTilde, buildNormalizedPath;
21     auto mmf = new MmFile(path.expandTilde.buildNormalizedPath,
22                           MmFile.Mode.read, 0, null, pageSize);
23     import nxt.byline : byLine, Newline;
24     return (cast(ElementType[])mmf[]).byLine!(Newline.native);
25 }