copyToSync method

void copyToSync(
  1. File other
)

Copies content of this to other file.

Implementation

void copyToSync(File other) {
  final otherSink = other.openSync(mode: FileMode.write);
  final thisStream = openRead();
  StreamSubscription<List<int>>? sub;
  sub = thisStream.listen(
    (data) => otherSink.writeFromSync(data),
    onDone: () {
      otherSink.close();
      sub?.cancel();
    },
    onError: (Object e) {
      otherSink.close();
      sub?.cancel();
      throw e;
    },
  );
}