Zig 0.17.0-dev (Split by item)

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 library itself.

unpackSourcesInner

fuzz.unpackSourcesInner
fn unpackSourcesInner(tar_bytes: []u8) !void

File

lib/build-web/fuzz.zig:218

Code

fn unpackSourcesInner(tar_bytes: []u8) !void {
    var tar_reader: std.Io.Reader = .fixed(tar_bytes);
    var file_name_buffer: [1024]u8 = undefined;
    var link_name_buffer: [1024]u8 = undefined;
    var it: std.tar.Iterator = .init(&tar_reader, .{
        .file_name_buffer = &file_name_buffer,
        .link_name_buffer = &link_name_buffer,
    });
    while (try it.next()) |tar_file| {
        switch (tar_file.kind) {
            .file => {
                if (tar_file.size == 0 and tar_file.name.len == 0) break;
                if (std.mem.endsWith(u8, tar_file.name, ".zig")) {
                    log.debug("found file: '{s}'", .{tar_file.name});
                    const file_name = try gpa.dupe(u8, tar_file.name);
                    // This is a hack to guess modules from the tar file contents. To handle modules
                    // properly, the build system will need to change the structure here to have one
                    // directory per module. This in turn requires compiler enhancements to allow
                    // the build system to actually discover the required information.
                    const mod_name, const is_module_root = p: {
                        if (std.mem.find(u8, file_name, "std/")) |i| break :p .{ "std", std.mem.eql(u8, file_name[i + 4 ..], "std.zig") };
                        if (std.mem.endsWith(u8, file_name, "/builtin.zig")) break :p .{ "builtin", true };
                        break :p .{ "root", std.mem.endsWith(u8, file_name, "/root.zig") };
                    };
                    const gop = try Walk.modules.getOrPut(gpa, mod_name);
                    const file: Walk.File.Index = @fromBackingInt(@intCast(Walk.files.entries.len));
                    if (!gop.found_existing or is_module_root) gop.value_ptr.* = file;
                    const file_bytes = tar_reader.take(@intCast(tar_file.size)) catch unreachable;
                    it.unread_file_bytes = 0; // we have read the whole thing
                    assert(file == try Walk.add_file(file_name, file_bytes));
                } else {
                    log.warn("skipping: '{s}' - the tar creation should have done that", .{tar_file.name});
                }
            },
            else => continue,
        }
    }
}