io::read_fully now handles unbounded streams properly

This commit is contained in:
Christoffer Lerno
2026-01-05 22:27:55 +01:00
parent d820a2356a
commit 702f836b40
4 changed files with 55 additions and 11 deletions

View File

@@ -0,0 +1,30 @@
module std::io @test;
struct Test (InStream)
{
char[] data;
int index;
}
fn char? Test.read_byte(&self) @dynamic
{
if (self.index >= self.data.len) return io::EOF~;
return self.data[self.index++];
}
fn usz? Test.read(&self, char[] buffer) @dynamic
{
io::printn(*self);
if (self.index >= self.data.len) return io::EOF~;
int len = min((int)self.data.len - self.index, 16);
buffer[:len] = self.data[self.index:len];
self.index += len;
return len;
}
fn void read_fully_stream()
{
Test t = { .data = "Heokep o opewkfpewkfpoew kfopwekfop ewkf ewopfkewop fopkewfopk ewopfkewpo fkopew kfpoewk fej!" };
char[] data = io::read_fully(tmem, &t)!!;
test::eq(data, t.data);
}