mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Merge c95d2b79b8 into 9082b004b6
This commit is contained in:
commit
7008ac6ac9
1 changed files with 12 additions and 0 deletions
|
|
@ -168,6 +168,10 @@ pub fn fixed(buffer: []const u8) Reader {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stream(r: *Reader, w: *Writer, limit: Limit) StreamError!usize {
|
pub fn stream(r: *Reader, w: *Writer, limit: Limit) StreamError!usize {
|
||||||
|
if (limit == .nothing) {
|
||||||
|
@branchHint(.unlikely);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
const buffer = limit.slice(r.buffer[r.seek..r.end]);
|
const buffer = limit.slice(r.buffer[r.seek..r.end]);
|
||||||
if (buffer.len > 0) {
|
if (buffer.len > 0) {
|
||||||
@branchHint(.likely);
|
@branchHint(.likely);
|
||||||
|
|
@ -1336,6 +1340,14 @@ test fixed {
|
||||||
try testing.expectError(error.EndOfStream, r.takeByte());
|
try testing.expectError(error.EndOfStream, r.takeByte());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "fixed: when streaming 0 bytes, return 0" {
|
||||||
|
var r: Reader = .fixed("i'm dying");
|
||||||
|
var trash: Writer.Discarding = .init(&.{});
|
||||||
|
|
||||||
|
const n = try r.stream(&trash.writer, .nothing);
|
||||||
|
try testing.expectEqual(n, 0);
|
||||||
|
}
|
||||||
|
|
||||||
test peek {
|
test peek {
|
||||||
var r: Reader = .fixed("abc");
|
var r: Reader = .fixed("abc");
|
||||||
try testing.expectEqualStrings("ab", try r.peek(2));
|
try testing.expectEqualStrings("ab", try r.peek(2));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue