stream.h cleanup & commenting

This commit is contained in:
Noel Berry
2021-01-14 12:21:59 -08:00
parent 2dcf902671
commit 261e2fd5e7
2 changed files with 50 additions and 43 deletions

View File

@ -26,4 +26,45 @@ int64_t Stream::pipe(Stream& stream, int64_t length)
}
return result;
}
}
// reads a string. if length < 0, assumes null-terminated
String Stream::read_string(int length)
{
String result;
if (length < 0)
{
char next;
while (read(&next, 1) && next != '\0')
result.append(next);
}
else
{
result.set_length(length);
read_into(result.cstr(), length);
}
return result;
}
String Stream::read_line()
{
String result;
char next;
while (read(&next, 1) && next != '\n' && next != '\0')
result.append(next);
return result;
}
int64_t Stream::write(const void* buffer, int64_t length)
{
return write_from(buffer, length);
}
int64_t Stream::write(const String& string)
{
return write_from(string.begin(), string.length());
}