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)
    @safe @safe
    immutable(void)[]
    rawReadZ
  2. immutable(void)[] rawReadZ(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