Function stream [src]

Prototype

pub fn stream(r: *Reader, w: *Writer, limit: Limit) StreamError!usize

Parameters

r: *Readerw: *Writerlimit: Limit

Possible Errors

EndOfStream

End of stream indicated from the Reader. This error cannot originate from the Writer.

ReadFailed

See the Reader implementation for detailed diagnostics.

WriteFailed

See the Writer implementation for detailed diagnostics.

Example

test stream { var out_buffer: [10]u8 = undefined; var r: Reader = .fixed("foobar"); var w: Writer = .fixed(&out_buffer); // Short streams are possible with this function but not with fixed. try testing.expectEqual(2, try r.stream(&w, .limited(2))); try testing.expectEqualStrings("fo", w.buffered()); try testing.expectEqual(4, try r.stream(&w, .unlimited)); try testing.expectEqualStrings("foobar", w.buffered()); }

Source

pub fn stream(r: *Reader, w: *Writer, limit: Limit) StreamError!usize { const buffer = limit.slice(r.buffer[r.seek..r.end]); if (buffer.len > 0) { @branchHint(.likely); const n = try w.write(buffer); r.seek += n; return n; } const n = try r.vtable.stream(r, w, limit); assert(n <= @intFromEnum(limit)); return n; }