readBytes method

  1. @override
Future<List<int>> readBytes(
  1. EaglePath path
)
override

Implementation

@override
Future<List<int>> readBytes(EaglePath path) async {
  try {
    final candidate = _lexical(path);
    final type = await FileSystemEntity.type(candidate, followLinks: false);
    if (type == FileSystemEntityType.notFound) {
      throw EagleSourceException('File does not exist: $path');
    }
    final resolved = await _resolvedContained(candidate, type);
    if (await FileSystemEntity.type(resolved) != FileSystemEntityType.file) {
      throw EagleSourceException('Path is not a file: $path');
    }
    return List<int>.unmodifiable(await File(resolved).readAsBytes());
  } on EagleSourceException {
    rethrow;
  } catch (error) {
    throw EagleSourceException('File cannot be read.', cause: error);
  }
}