unpack method Null safety

void unpack(
  1. String pathTo
)

Unpacks a resource saving it to the file at pathTo.

Implementation

void unpack(String pathTo) {
  if (exists(pathTo) && !isFile(pathTo)) {
    throw ResourceException('The unpack target $pathTo must be a file');
  }
  final normalized = normalize(pathTo);
  if (!exists(dirname(normalized))) {
    createDir(dirname(normalized), recursive: true);
  }

  final file = waitForEx(File(normalized).open(mode: FileMode.write));

  try {
    for (final line in content.split('\n')) {
      if (line.trim().isNotEmpty) {
        waitForEx(file.writeFrom(base64.decode(line)));
      }
    }
  } finally {
    waitForEx<dynamic>(file.flush());
    file.close();
  }
}