flush method

Future<void> flush()

Writes the buffered content to the output file and clears the buffer.

The output file will include a part directive that points back to the original input file. If the buffer is empty, no file is written.

@return A future that completes when the file has been written

Implementation

Future<void> flush() async {
  if (_buffer.isEmpty) return;
  final String partOf = p.relative(
    asset.uri.path,
    from: p.dirname(outputUri.path),
  );
  final String header = <String>[defaultFileHeader, "part of '$partOf';"].join('\n\n');
  final String content = _buffer.toString();

  final File outputFile = File.fromUri(outputUri);
  await outputFile.writeAsString('$header\n\n$content');
  _buffer.clear();
  outputs.add(outputUri);
}