persistOutput method

Future<File> persistOutput(
  1. File source, {
  2. required String fileName,
})

Copies a standalone output, such as a merged multi-room USDZ, into persistent app storage and returns its durable file path.

Implementation

Future<File> persistOutput(File source, {required String fileName}) async {
  final cleanName = fileName.trim();
  if (cleanName.isEmpty ||
      cleanName.contains('/') ||
      cleanName.contains('\\')) {
    throw ArgumentError.value(fileName, 'fileName', 'Use a plain file name.');
  }
  final root = await _rootDirectory();
  final exports = Directory('${root.path}/exports');
  await exports.create(recursive: true);
  final target = File('${exports.path}/${_newId()}-$cleanName');
  if (!await source.exists() || await source.length() == 0) {
    throw FileSystemException(
      'Cannot save a missing or empty output.',
      source.path,
    );
  }
  return source.copy(target.path);
}