saveFile method

File saveFile(
  1. File file, {
  2. String? filename,
})

Saves the file in the vault.

Implementation

File saveFile(File file, {String? filename}) {
  unlock();
  final outFile = filename != null
      ? location.file(filename)
      : location.file('${file.name}.gpg');
  if (!outFile.path.endsWith('.gpg')) {
    throw 'Files in vault are required to end with ".gpg". '
        '"$filename" does not';
  }
  if (!file.existsSync()) {
    if (file.isAbsolute) {
      throw "${file.path} does not exist";
    } else {
      throw "${file.path} does not exist in ${Directory.current.path}";
    }
  }
  return gpgEncrypt(file, _passphrase!, output: outFile);
}