This commit is contained in:
2025-12-01 23:39:14 +01:00
parent 8380ae5863
commit 126cc23d18
2 changed files with 29 additions and 0 deletions

28
src/utils/loadpuzzle.zig Normal file
View File

@@ -0,0 +1,28 @@
const std = @import("std");
pub fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]u8 {
var file = try std.fs.cwd().openFile(path, .{});
defer file.close();
var fatfuckingstr = std.Io.Writer.Allocating.init(allocator);
defer fatfuckingstr.deinit();
var buffer: [1024]u8 = undefined;
var reader = file.reader(&buffer);
const actual_reader = &reader.interface;
_ = try actual_reader.stream(&fatfuckingstr.writer, .unlimited);
return fatfuckingstr.toOwnedSlice();
}
test "reader_test" {
const alloc = std.testing.allocator;
const contents = try readFile("test.txt", alloc);
defer alloc.free(contents);
try std.testing.expectEqualStrings("Hello World!", contents);
}

1
test.txt Normal file
View File

@@ -0,0 +1 @@
Hello World!