aboutsummaryrefslogtreecommitdiff
path: root/src/stream/root.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/stream/root.zig')
-rw-r--r--src/stream/root.zig33
1 files changed, 33 insertions, 0 deletions
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(),
+ };
+ }
+};