From 6201307fecf8398a1b53bf276bc08bfbb3524899 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 17 Nov 2025 13:09:02 +0100 Subject: implement memora.Stream --- src/stream/root.zig | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/stream/root.zig (limited to 'src/stream/root.zig') diff --git a/src/stream/root.zig b/src/stream/root.zig new file mode 100644 index 0000000..11580ac --- /dev/null +++ b/src/stream/root.zig @@ -0,0 +1,33 @@ +const std = @import("std"); + +pub const Stream = union(enum) { + const Self = @This(); + + pub const File = @import("file.zig"); + pub const Buffer = @import("buffer.zig"); + + file: File, + buffer: Buffer, + + pub fn from_file(file: std.fs.File) Self { + return .{ .file = File.init(file) }; + } + + pub fn from_buffer(buffer: []const u8) Self { + return .{ .buffer = Buffer.init(buffer) }; + } + + pub fn reader(self: *Self, buffer: []u8) *std.Io.Reader { + return switch(self.*) { + .file => |*f| f.reader(buffer), + .buffer => |*b| b.reader(buffer), + }; + } + + pub fn close(self: *Self) void { + return switch(self.*) { + .file => |*f| f.close(), + .buffer => |*b| b.close(), + }; + } +}; -- cgit v1.2.3-70-g09d2