rawReadZ

Read file path into raw array with one extra terminating zero byte.

This extra terminating zero (null) byte at the end is typically used as a sentinel value to speed up textual parsers or when characters are sent to a C-function taking a zero-terminated string as input.

TODO: Add or merge to Phobos?

  1. immutable(void)[] rawReadZ(FilePath path)
  2. immutable(void)[] rawReadZ(File file)
    @safe @trusted
    immutable(void)[]
    rawReadZ
    (
    scope File file
    )

Examples

import nxt.algorithm.searching : endsWith;
const d = cast(const(char)[]) FilePath(`/etc/passwd`).rawReadZ();
assert(d.endsWith('\0')); // has 0-terminator

See Also

Meta