writeTo method

bool writeTo({
  1. File? file,
  2. String? chmod,
  3. bool noClobber = false,
})

Write the asset content to the specified file, or the targetPath if null, optionally setting permissions specified in chmod. If the file exists and noClobber is true, specified permissions will still be set but the file won't be overwritten.

Implementation

bool writeTo({File? file, String? chmod, bool noClobber = false}) {
  final safeFile = file ?? File(targetPath);
  if (!safeFile.parent.existsSync()) {
    safeFile.parent.createSync(recursive: true);
  }
  if (!noClobber || !safeFile.existsSync()) {
    safeFile.writeAsStringSync(_contents);
  }
  if (chmod != null) {
    Utils.chmod(chmod, safeFile.path);
  }
  return safeFile.existsSync();
}