newSink method

Future<Sink> newSink(
  1. int index
)

Returns a new unbuffered output stream to write the value at index. If the underlying output stream encounters errors when writing to the filesystem, this edit will be aborted when commit is called.

Implementation

Future<Sink> newSink(int index) {
  return _cache._lock.synchronized(() async {
    if (_done) throw StateError('editor was done');
    if (_entry.currentEditor != this) {
      return BlackHoleSink();
    }
    if (!_entry.readable) {
      _written![index] = true;
    }
    final dirtyFile = _entry.getDirtyFile(index);
    final Sink sink;
    try {
      sink = await _cache.fileSystem.openSink(dirtyFile, recursive: true);
    } on FileSystemException {
      return BlackHoleSink();
    }
    return FaultHidingSink(
      sink,
      () => _cache._lock.synchronized(() => _detach()),
    );
  });
}