lib/std/io/stream: add LimitReader (#858)

* lib/std/io/stream: add LimitReader

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

* lib/std: more method conversions to use new receiver notation

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

---------

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2023-07-17 20:22:29 +02:00
committed by GitHub
parent 209d994336
commit fd5336c56e
16 changed files with 266 additions and 210 deletions

View File

@@ -0,0 +1,20 @@
module std::io @test;
fn void! limitreader()
{
const DATA = "Hello World!";
ByteReader src;
src.init(DATA);
const LIMIT = 5;
LimitReader lmr;
lmr.init(src.as_stream(), LIMIT);
char[DATA.len] bytes;
usz n = lmr.read(bytes[..])!;
assert(n == LIMIT, "got %d; want %d", n, LIMIT);
String got = (String)bytes[:n];
String want = DATA[:LIMIT];
assert(got == want, "got %d; want %d", got, want);
}