Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

readFileAlloc

Public Function
std.Io.Dir.readFileAlloc
pub fn readFileAlloc(
    dir: Dir,
    io: Io,
    /// On Windows, should be encoded as [WTF-8](https://wtf-8.codeberg.page/).
    /// On WASI, should be encoded as valid UTF-8.
    /// On other platforms, an opaque sequence of bytes with no particular encoding.
    sub_path: []const u8,
    /// Used to allocate the result.
    gpa: Allocator,
    /// If reached or exceeded, `error.StreamTooLong` is returned instead.
    limit: Io.Limit,
) ReadFileAllocError![]u8

Reads all the bytes from the named file. On success, caller owns returned buffer.

If the file size is already known, a better alternative is to initialize a File.Reader.

If the file size cannot be obtained, an error is returned. If this is a realistic possibility, a better alternative is to initialize a File.Reader which handles this seamlessly.

Params

  • dir: Dir
  • io: Io
  • sub_path: []const u8

    On Windows, should be encoded as WTF-8. On WASI, should be encoded as valid UTF-8. On other platforms, an opaque sequence of bytes with no particular encoding.

  • gpa: Allocator

    Used to allocate the result.

  • limit: Io.Limit

    If reached or exceeded, error.StreamTooLong is returned instead.

File

Io/Dir.zig:1330
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
pub fn readFileAlloc(
    dir: Dir,
    io: Io,
    /// On Windows, should be encoded as [WTF-8](https://wtf-8.codeberg.page/).
    /// On WASI, should be encoded as valid UTF-8.
    /// On other platforms, an opaque sequence of bytes with no particular encoding.
    sub_path: []const u8,
    /// Used to allocate the result.
    gpa: Allocator,
    /// If reached or exceeded, `error.StreamTooLong` is returned instead.
    limit: Io.Limit,
) ReadFileAllocError![]u8 {
    return readFileAllocOptions(dir, io, sub_path, gpa, limit, .of(u8), null);
}