getPackageDirectory method
Future<String>
getPackageDirectory(
- WindowsMetadataPackage package,
- String version,
- Future<
Uint8List> downloadFunction(), { - Logger? logger,
Fetches the package directory, downloading and extracting it if necessary.
- Checks if the package exists locally.
- If absent, downloads the package via
downloadFunction
. - Extracts the archive contents into a new directory.
- Optionally logs progress if a
logger
is provided.
Returns the absolute package directory path.
Implementation
Future<String> getPackageDirectory(
WindowsMetadataPackage package,
String version,
Future<Uint8List> Function() downloadFunction, {
Logger? logger,
}) async {
final packagePath = _packagePath(package, version);
final metadataPath = p.join(packagePath, package.assetName);
if (File(metadataPath).existsSync()) return packagePath;
Directory(packagePath).createSync(recursive: true);
logger?.info('Downloading "$package" version "$version"...');
final downloadTimer = Stopwatch()..start();
final archiveBytes = await downloadFunction();
downloadTimer.stop();
logger?.info(
'Download complete: '
'${(archiveBytes.lengthInBytes / (1024 * 1024)).toStringAsFixed(1)} MB '
'in ${(downloadTimer.elapsedMilliseconds / 1000.0).toStringAsFixed(1)} '
'seconds.',
);
logger?.info('Extracting archive...');
final extractionTimer = Stopwatch()..start();
final archive = ZipDecoder().decodeBytes(archiveBytes);
extractArchiveToDiskSync(archive, packagePath);
extractionTimer.stop();
logger?.info(
'Extraction completed in '
'${(extractionTimer.elapsedMilliseconds / 1000.0).toStringAsFixed(1)} '
'seconds.',
);
return packagePath;
}