copyOutput method

Future<void> copyOutput(
  1. AssetId id,
  2. AssetWriter writer,
  3. {bool requireContent = false}
)

Copies id from the tmp dir and writes it back using the writer.

Note that BuildStep implements AssetWriter and that is typically what you will want to pass in.

This must be called for all outputs which you want to be included as a part of the actual build (any other outputs will be deleted with the tmp dir and won't be available to other Builders).

If requireContent is true and the file is empty an EmptyOutputException is thrown.

Implementation

Future<void> copyOutput(AssetId id, AssetWriter writer,
    {bool requireContent = false}) async {
  var file = fileFor(id);
  var bytes = await _descriptorPool.withResource(file.readAsBytes);
  if (requireContent && bytes.isEmpty) throw EmptyOutputException(id);
  await writer.writeAsBytes(id, bytes);
}