# available method

1. @override

Future<int> available()
override

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

## Returns

An estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, or `0` when it reaches the end of the input stream.

## Example

    final input = FileInputStream('data.bin');
    try {
      final available = await input.available();
      print('Approximately $available bytes available');

      if (available > 0) {
        final buffer = Uint8List(available.clamp(1, 8192));
        final bytesRead = await input.read(buffer);
        processData(buffer.sublist(0, bytesRead));
      }
    } finally {
      await input.close();
    }

Throws IOException if an I/O error occurs. Throws StreamClosedException if the stream has been closed.

## Implementation

    @override
    Future<int> available() async {
      checkClosed();
      // For a network stream, we can only reliably report what's already buffered.
      // We cannot predict how much more data is coming without blocking.
      return _buffer.length - _bufferOffset;
    }