aboutsummaryrefslogtreecommitdiff
path: root/lib/std/io/out_stream.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/io/out_stream.zig')
-rw-r--r--lib/std/io/out_stream.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/std/io/out_stream.zig b/lib/std/io/out_stream.zig
index 7f534865f5..cb75b27bf1 100644
--- a/lib/std/io/out_stream.zig
+++ b/lib/std/io/out_stream.zig
@@ -14,13 +14,13 @@ pub fn OutStream(comptime WriteError: type) type {
const Self = @This();
pub const Error = WriteError;
pub const WriteFn = if (std.io.is_async)
- async fn (self: *Self, bytes: []const u8) Error!void
+ async fn (self: *Self, bytes: []const u8) Error!usize
else
- fn (self: *Self, bytes: []const u8) Error!void;
+ fn (self: *Self, bytes: []const u8) Error!usize;
writeFn: WriteFn,
- pub fn write(self: *Self, bytes: []const u8) Error!void {
+ pub fn writeOnce(self: *Self, bytes: []const u8) Error!usize {
if (std.io.is_async) {
// Let's not be writing 0xaa in safe modes for upwards of 4 MiB for every stream write.
@setRuntimeSafety(false);
@@ -31,6 +31,13 @@ pub fn OutStream(comptime WriteError: type) type {
}
}
+ pub fn write(self: *Self, bytes: []const u8) Error!void {
+ var index: usize = 0;
+ while (index != bytes.len) {
+ index += try self.writeOnce(bytes[index..]);
+ }
+ }
+
pub fn print(self: *Self, comptime format: []const u8, args: var) Error!void {
return std.fmt.format(self, Error, write, format, args);
}