# dmd.root.file

Read a `file` from disk and store it in memory.

#### Authors

Walter Bright, https://www.digitalmars.com

#### License

Boost License 1.0

Source: root/file.d

Documentation: https://dlang.org/phobos/dmd_root_file.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/root/file.d

- `FileBuffer`

  #### Declaration

  `struct `FileBuffer`;`

  Owns a (rmem-managed) file buffer.

  - `extractSlice`

    #### Declaration

    `pure nothrow @nogc @safe ubyte[] `extractSlice`();`

    Transfers ownership of the buffer to the caller.

- `File`

  #### Declaration

  `struct `File`;`

  - `ReadResult`

    #### Declaration

    `struct `ReadResult`;`

    - `extractSlice`

      #### Declaration

      `pure nothrow @nogc @safe ubyte[] `extractSlice`();`

      Transfers ownership of the buffer to the caller.

    - `extractDataZ`

      #### Declaration

      `pure nothrow @nogc ubyte[] `extractDataZ`();`

      ditto Include the `null`-terminator at the end of the buffer in the returned array.

  - `read`

    #### Declaration

    `static nothrow ReadResult `read`(const(char)* `name`);
    static nothrow ReadResult `read`(const(char)[] `name`);`

    Read the full content of a file.

  - `write`

    #### Declaration

    `static nothrow bool `write`(const(char)* `name`, const void[] `data`);
    static nothrow bool `write`(const(char)[] `name`, const void[] `data`);
    static nothrow bool `write`(const(char)* `name`, const(void)* `data`, size_t `size`);`

    Write a file, returning `true` on success.

  - `remove`

    #### Declaration

    `static nothrow void `remove`(const(char)* `name`);`

    Delete a file.

  - `update`

    #### Declaration

    `static nothrow bool `update`(const(char)* `namez`, const void[] `data`);
    static nothrow bool `update`(const(char)[] `name`, const void[] `data`);
    static nothrow bool `update`(const(char)* `name`, const(void)* `data`, size_t `size`);`

    Update file

    #### Discussion

    If the file exists and is identical to what is to be written, merely `update` the timestamp on the file. Otherwise, write the file.
    The idea is writes are much slower than reads, and build systems often wind up generating identical files.

    #### Parameters

    `const(char)[] `name`` | `name` of file to `update`
    `void[] `data`` | updated contents of file

    #### Return Value

    `true` on success

  - `size`

    #### Declaration

    `static nothrow ulong `size`(const char* `namez`);`

    Size of a file in bytes.

    #### Parameters

    `char* `namez`` | `null`-terminated filename

    #### Return Value

    `ulong.max` on any error, the length otherwise.