mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add io::read_new_fully for reading to the end of a stream. Add io::wrap_bytes for reading bytes with io functions.
This commit is contained in:
@@ -77,6 +77,22 @@ macro usz! read_all(stream, char[] buffer)
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @require @is_instream(stream)
|
||||
*/
|
||||
macro char[]! read_new_fully(stream, Allocator allocator = allocator::heap())
|
||||
{
|
||||
usz len = available(stream)!;
|
||||
char* data = allocator::malloc_try(allocator, len)!;
|
||||
defer catch allocator::free(allocator, data);
|
||||
usz read = 0;
|
||||
while (read < len)
|
||||
{
|
||||
read += stream.read(data[read:len - read])!;
|
||||
}
|
||||
return data[:len];
|
||||
}
|
||||
|
||||
/**
|
||||
* @require @is_outstream(stream)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user