extractZipArchive function
Asynchronously extracts a Zip archive into the specified directory.
if the optional callback
is specified, it will be called for every
extracted file after the extraction has been completed.
Implementation
Future<void> extractZipArchive(File archive, Directory dir,
{void Function(ZipEntry entry, int totalEntries)? callback}) async {
final receivePort = ReceivePort();
final sendPort = receivePort.sendPort;
Isolate.spawn((args) {
extractZipArchiveSync(archive, dir, callback: (entry, totalEntries) {
sendPort.send((entry, totalEntries));
});
sendPort.send(null);
}, null);
await for (final message in receivePort) {
switch (message) {
case (ZipEntry entry, int totalEntries):
callback?.call(entry, totalEntries);
default:
receivePort.close();
break;
}
}
}