diff --git a/build.zig b/build.zig index 0e916a4..658dca6 100644 --- a/build.zig +++ b/build.zig @@ -6,12 +6,14 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); - const exe = b.addExecutable(.{ - .name = "zdotenv", - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - }); + const main_module = + b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }); + + const exe = b.addExecutable(.{ .name = "zdotenv", .root_module = main_module }); // For setting env vars using C exe.linkLibC(); @@ -20,8 +22,7 @@ pub fn build(b: *std.Build) void { // Module setup _ = b.addModule("zdotenv", .{ .root_source_file = b.path("src/main.zig") }); var lib_tests = b.addTest(.{ - .root_source_file = b.path("src/main.zig"), - .optimize = optimize, + .root_module = main_module, }); const test_step = b.step("test", "Run library tests"); diff --git a/build.zig.zon b/build.zig.zon index 3674729..b3f32f5 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -6,7 +6,8 @@ // // It is redundant to include "zig" in this name because it is already // within the Zig package namespace. - .name = "zdotenv", + .name = .zdotenv, + .fingerprint = 0xb52a51eb5af5b8cc, // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. diff --git a/src/parser.zig b/src/parser.zig index db7bb5f..9b7268e 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -18,7 +18,9 @@ pub const Parser = struct { // parse is a simple parsing function. Its simple on purpose, this process should not be lofty or complex. No AST's or complex symbol resolution. Just take the Key and Value from the K=V from an .env and avoid comments (#) pub fn parse(self: *Self) !std.StringHashMap([]const u8) { var buf: [1024 * 2 * 2]u8 = undefined; - while (try self.file.reader().readUntilDelimiterOrEof(&buf, '\n')) |line| { + var reader = self.file.reader(&buf); + + while (reader.interface.takeDelimiterExclusive('\n')) |line| { // Skip comments (i.e. #) if (std.mem.startsWith(u8, line, "#")) continue; if (std.mem.eql(u8, line, "")) continue; @@ -36,6 +38,9 @@ pub const Parser = struct { const d_val = try self.allocator.dupe(u8, value); try self.env_values.put(d_key, d_val); + } else |err| { + if (err != error.EndOfStream) + return err; } return self.env_values;