skip method
Skips characters.
This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.
Parameters
n
: The number of characters to skip
Returns
The number of characters actually skipped.
Example
final reader = FileReader('data.txt');
try {
// Skip the first 100 characters (e.g., header)
final skipped = await reader.skip(100);
print('Skipped $skipped characters');
// Now read the actual content
final content = await reader.readAll();
processContent(content);
} finally {
await reader.close();
}
Throws IOException if an I/O error occurs. Throws StreamClosedException if the reader has been closed.
Implementation
@override
Future<int> skip(int n) async {
await _ensureOpen();
if (n <= 0 || _buffer == null) {
return 0;
}
final availableChars = _buffer!.length - _bufferPosition;
final charsToSkip = n.clamp(0, availableChars);
_bufferPosition += charsToSkip;
return charsToSkip;
}