A small Zig library for embedding directory trees with @embedFile. ISSUE TRACKER: https://todo.sr.ht/~dermetfan/embed-dir
add usage example for files array to README
add array of file names
fix for zig 0.6.0

heads

tip
browse log

clone

read-only
https://hg.sr.ht/~dermetfan/embed-dir
read/write
ssh://hg@hg.sr.ht/~dermetfan/embed-dir

#embed-dir

A small Zig library for embedding directory trees with @embedFile.

Generates a Zig source file that you can import into your code.

#Usage

In build.zig:

const embed_dir = @import("embed-dir/lib.zig");

pub fn build(b: *Builder) !void {
    // …

    try embed_dir.writeZig(std.heap.page_allocator, .{
        .target = "src/embed.zig", // default
        .dir = "www",
    });
}

Your code:

const embed = @import("embed.zig");

pub fn main() !void {
    const index = embed.get("index.html").?;

    // or allocate a HashMap:

    const map = embed.initMap(std.heap.page_allocator);
    defer map.deinit();

    const index = map.getValue("index.html").?;

    // array of embedded files:

    for (embed.files) |file| std.debug.warn("{}\n", .{file});
}