computeFileDiff method

Future<FileDiff> computeFileDiff(
  1. String oldPath,
  2. String newPath
)

Compute a FileDiff by reading files at oldPath and newPath.

Implementation

Future<FileDiff> computeFileDiff(String oldPath, String newPath) async {
  final oldFile = File(oldPath);
  final newFile = File(newPath);
  final oldText = await oldFile.exists() ? await oldFile.readAsString() : '';
  final newText = await newFile.exists() ? await newFile.readAsString() : '';

  final hunks = computeDiff(oldText, newText);
  final stats = _computeStats(hunks);
  return FileDiff(
    path: newPath,
    oldPath: oldPath,
    hunks: hunks,
    stats: stats,
  );
}