append method

  1. @override
Future<void> append(
  1. String ref,
  2. String line
)
override

Add one line to the end.

Separate from write because history and chat are append-only, and rewriting the whole record to add a line costs the whole record on every turn.

Implementation

@override
Future<void> append(String ref, String line) async {
  final file = await _fileHandle(ref, create: true);
  final existing = await file!.getFile().toDart;
  final end = existing.size;
  final writable = await file
      .createWritable(web.FileSystemCreateWritableOptions(
        keepExistingData: true,
      ))
      .toDart;
  await writable.seek(end).toDart;
  await writable.write(line.toJS).toDart;
  await writable.close().toDart;
}