close method
Finish decoding at EOF.
- Drains all remaining complete frames via
tryDecodeBorrowed. - If the codec mixes in FinalizableCodec, calls
tryFinalizerepeatedly to flush any final frame (wrapped as owned views). - If trailing bytes remain and
allowTrailingBytesAtEofisfalse, throws FormatException.
Implementation
void close(
void Function(FrameBorrowedView frame) onFrame, {
bool allowTrailingBytesAtEof = false,
}) {
_drain(onFrame);
// Let the codec finalize (emit trailing frame at EOF).
if (codec is FinalizableCodec<Uint8List>) {
final c = codec as FinalizableCodec<Uint8List>;
while (true) {
final bytes = c.tryFinalize(_rb);
if (bytes == null) break;
onFrame(FrameBorrowedView.owned(bytes));
}
}
if (!allowTrailingBytesAtEof && (_rb.length != 0 || codec.hasPending)) {
final pendingNote = codec.hasPending ? ' (codec has pending state)' : '';
throw FormatException(
'Truncated frame at EOF: ${_rb.length} trailing bytes buffered'
'$pendingNote.',
);
}
}