parts method
The files the manifest declares under parts, read from beside it.
Empty for a model whose weights fit inside its graph, which is nearly all of them, so a caller can pass this to a runtime without asking which shape of bundle it holds.
Implementation
Future<Map<String, Uint8List>> parts() async {
if (manifest.parts.isEmpty) return const {};
final dir = bundleRoot;
if (dir == null) {
throw StateError(
'the manifest for "${manifest.name}" declares '
'${manifest.parts.length} part(s), and this bundle was built without a '
'directory to read them from. Open it with '
'DirectoryGoldenBundle.open so the parts come from beside the manifest.',
);
}
final read = <String, Uint8List>{};
for (final part in manifest.parts) {
final file = File('$dir/${part.name}');
if (!file.existsSync()) {
// Named rather than left to the loader. Both files travel together or
// neither is usable, and the one that goes missing is the one carrying
// the numbers: the graph alone still parses and still answers.
throw BundlePartMissingException(
missing: [part.name],
model: manifest.name,
);
}
read[part.name] = await file.readAsBytes();
}
return read;
}