replace method

Future<void> replace(
  1. String svgPath,
  2. String existing,
  3. String replacement
)

Implementation

Future<void> replace(
    String svgPath, String existing, String replacement) async {
  try {
    log('replace on $svgPath');
    final svgFile = File(svgPath);
    final lines = load();

    final backupPath = '$svgPath.bak';
    final backupFile = File(backupPath);
    final backup = backupFile.openWrite();

    for (final line in lines) {
      backup.writeln(line.replaceAll(existing, replacement));
    }

    await backup.flush();
    await backup.close();

    svgFile.deleteSync();

    backupFile.renameSync(svgPath);
    log('replace complete $svgPath');
    // ignore: avoid_catches_without_on_clauses
  } catch (e, st) {
    log('Excepton in replace: $e, $st');
  }
}