readToEnd method
Reads until EOF, returning an immutable view over the accumulated data.
Implementation
Future<Bytes> readToEnd({int? limit}) async {
final out = BytesMut();
while (true) {
if (limit != null && out.length >= limit) {
throw LimitExceeded(limit);
}
final take = limit == null
? 64 * 1024
: (limit - out.length).clamp(1, 64 * 1024);
final spare = out.spareView(take);
final dst = ReadBuf(spare);
final result = await readInto(dst);
out.advance(dst.filled);
if (result.eof && dst.filled == 0) break;
if (result.bytes == 0) break;
}
return out.freeze();
}