sink method

Future<Sink> sink(
  1. String path, {
  2. FileMode mode = FileMode.write,
  3. bool recursive = false,
})

Creates a Sink that writes bytes to path from beginning to end. If path already exists it will be replaced with the new data.

Implementation

Future<Sink> sink(
  String path, {
  FileMode mode = FileMode.write,
  bool recursive = false,
}) async {
  if (mode != FileMode.write &&
      mode != FileMode.append &&
      mode != FileMode.writeOnly &&
      mode != FileMode.writeOnlyAppend) {
    throw ArgumentError('Invalid file mode for this operation');
  }
  if (recursive) {
    await directory(p.dirname(path)).create(recursive: true);
  }
  return file(path).openWrite(mode: mode).sink();
}