| ... | ... | @@ -518,6 +518,17 @@ test "writeSplatAll works with a single buffer" { |
| 518 | 518 | try testing.expectEqualStrings("hellohellohello", aw.writer.buffered()); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | /// Transfers `bytes` to the stream, calling `drain` at most once. |
| 522 | /// |
| 523 | /// Returns the number of bytes transferred, which may be less than |
| 524 | /// `bytes.len`, including zero. |
| 525 | /// |
| 526 | /// A return value less than `bytes.len` does not indicate failure; a |
| 527 | /// subsequent call may return nonzero, or fail with `error.WriteFailed`. |
| 528 | /// |
| 529 | /// See also: |
| 530 | /// * `writeAll` |
| 531 | /// * `writeVec` |
| 521 | 532 | pub fn write(w: *Writer, bytes: []const u8) Error!usize { |
| 522 | 533 | if (w.end + bytes.len <= w.buffer.len) { |
| 523 | 534 | @branchHint(.likely); |
| ... | ... | @@ -528,8 +539,13 @@ pub fn write(w: *Writer, bytes: []const u8) Error!usize { |
| 528 | 539 | return w.vtable.drain(w, &.{bytes}, 1); |
| 529 | 540 | } |
| 530 | 541 | |
| 531 | | /// Calls `drain` as many times as necessary such that all of `bytes` are |
| 532 | | /// transferred. |
| 542 | /// Transfers `bytes` to the stream, calling `drain` as many times as necessary |
| 543 | /// such that all `bytes` are transferred. |
| 544 | /// |
| 545 | /// See also: |
| 546 | /// * `print` |
| 547 | /// * `writeVecAll` |
| 548 | /// * `write` |
| 533 | 549 | pub fn writeAll(w: *Writer, bytes: []const u8) Error!void { |
| 534 | 550 | var index: usize = 0; |
| 535 | 551 | while (index < bytes.len) index += try w.write(bytes[index..]); |