skip method
Skips over and discards n
bytes of data from this input stream.
The skip method may, for a variety of reasons, end up skipping over
some smaller number of bytes, possibly 0
. This may result from any of
a number of conditions; reaching end of file before n
bytes have been
skipped is only one possibility.
Parameters
n
: The number of bytes to be skipped
Returns
The actual number of bytes skipped.
Example
final input = FileInputStream('data.bin');
try {
// Skip the first 100 bytes (e.g., header)
final skipped = await input.skip(100);
print('Skipped $skipped bytes');
// Now read the actual data
final data = await input.readAll();
processData(data);
} finally {
await input.close();
}
Throws IOException if an I/O error occurs. Throws StreamClosedException if the stream has been closed.
Implementation
@override
Future<int> skip(int n) async {
checkClosed();
if (n <= 0) {
return 0;
}
final available = _buffer.length - _position;
final bytesToSkip = n < available ? n : available;
_position += bytesToSkip;
return bytesToSkip;
}