saveFromPath method

Future<PasskitFile> saveFromPath({
  1. required String id,
  2. required File file,
})

Implementation

Future<PasskitFile> saveFromPath({
  required String id,
  required File file,
}) async {
  final directory = await fs.createDirectory(name: directoryName);
  final childDirectory = Directory(Path.withoutExtension(file.path));

  if (directory.path == Path.dirname(file.path)) {
    throw Exception('This file has already been saved.');
  }

  if (!file.existsSync()) {
    throw Exception('Unable to fetch pass file at specified path');
  }

  file.copySync('${directory.path}/$id.passkit');
  await fs.unpack(path: '${directory.path}/$id.passkit');

  final passFile = File('${directory.path}/$id/pass.json');
  if (!passFile.existsSync()) throw Exception('Missing pass.json');

  return Parser(
    id: id,
    directory: childDirectory,
    passFile: passFile,
    file: file,
  ).parse();
}