setInfo method

  1. @override
Future<void> setInfo(
  1. String name,
  2. String key,
  3. I info
)

Sets the partition info indexed by key.

  • name: The partition name
  • key: The key
  • info: The info

Implementation

@override
Future<void> setInfo(String name, String key, I info) {
  return _adapter
      .partitionFile(name, key)
      .open(mode: FileMode.append)
      .then((raf) {
    final pre = lock
        ? (RandomAccessFile f) => f.lock(FileLock.blockingExclusive)
        : (RandomAccessFile f) => Future.value(f);
    final pos =
        lock ? () => raf.unlock().then((f) => f.close()) : () => raf.close();

    return pre(raf)
        .then((f) => f.setPosition(0))
        .then((f) => f.writeFrom(_writeInfo(info).takeBytes()))
        .whenComplete(pos)
        .then((_) => null);
  });
}