unpack method

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);
  }

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

  try {
    for (final line in content.split('\n')) {
      if (line.trim().isNotEmpty) {
        // ignore: discarded_futures
        waitForEx(file.writeFrom(base64.decode(line)));
      }
    }
  } finally {
    // ignore: discarded_futures
    waitForEx(file.flush());
    // ignore: discarded_futures
    waitForEx(file.close());
  }
}