readBinaryFile method

  1. @override
Future<Result<Uint8List, FileError>> readBinaryFile(
  1. String path
)
override

Reads the file as raw bytes.

Implementation

@override
Future<Result<Uint8List, FileError>> readBinaryFile(String path) async {
  final resolved = _resolve(path);
  try {
    final stat = await FileStat.stat(resolved);
    if (stat.type == FileSystemEntityType.directory) {
      return Err(
        FileError(
          FileErrorCode.isDirectory,
          'Is a directory',
          path: resolved,
        ),
      );
    }
    return Ok(await File(resolved).readAsBytes());
  } on Object catch (error) {
    return Err(_toFileError(error, resolved));
  }
}