length property

  1. @override
int get length
override

The length of the file in bytes, or -1 for a directory or non-existing files.

Implementation

@override
int get length {
  try {
    // For VM platforms with IO file
    final ioFile = _ioFile;
    if (ioFile != null) {
      return ioFile.lengthSync();
    }

    // For web, XFile.length returns a Future<int>, but we need sync access.
    // This is a limitation - on web, we return -1 to indicate unknown length.
    // Users should use lengthAsync() for web compatibility.
    return -1;
  } catch (e) {
    return -1;
  }
}