open static method

Future<FileByteSource> open(
  1. String path
)

Opens path for random-access reads and snapshots its initial length.

Implementation

static Future<FileByteSource> open(String path) async {
  final file = File(path);
  RandomAccessFile? handle;
  try {
    handle = await file.open(mode: FileMode.read);
    final length = await handle.length();
    ByteRange(0, length);
    return FileByteSource._(file, handle, length);
  } on ByteIoException {
    await handle?.close();
    rethrow;
  } on FileSystemException catch (error) {
    await handle?.close();
    throw ByteSourceIoException(
      operation: 'open byte source',
      cause: error,
      location: path,
    );
  }
}