consolidate AssetBundle::entries and AssetBundle::entryKinds into a new type, AssetBundleEntry (#142029)

Part of work on https://github.com/flutter/flutter/pull/141194

The [`AssetBundle`](0833929c99/packages/flutter_tools/lib/src/asset.dart (L80)) class contains two members, `entries` and `entryKinds`. `entries` contains asset data indexed by asset key. `entryKinds` contains the "kinds" of these assets, again indexed by asset key.

**Change.** Rather than have two separate maps, this PR proposes combining these maps into one by wrapping the asset data and kind into a single data type `AssetBundleEntry`.

**Purpose.** In https://github.com/flutter/flutter/pull/141194, I am considering associating more information with an asset. In particular, what transformers are meant to be applied to it when copying it to the build output. Rather than adding another map member onto `AssetBundle` (e.g. `entryTransformers`), I decided to make things neater by introducing the `AssetBundleEntry` type.
This commit is contained in:
Andrew Kolos
2024-01-23 14:00:46 -08:00
committed by GitHub
parent 2bd5abf829
commit cbe0ceafe2
9 changed files with 127 additions and 104 deletions

View File

@@ -14,7 +14,6 @@ import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/bundle_builder.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/context_runner.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/reporting/reporting.dart';
@@ -37,9 +36,9 @@ Future<void> main(List<String> args) {
});
}
Future<void> writeFile(libfs.File outputFile, DevFSContent content) async {
Future<void> writeAssetFile(libfs.File outputFile, AssetBundleEntry asset) async {
outputFile.createSync(recursive: true);
final List<int> data = await content.contentsAsBytes();
final List<int> data = await asset.contentsAsBytes();
outputFile.writeAsBytesSync(data);
}
@@ -73,9 +72,9 @@ Future<void> run(List<String> args) async {
}
final List<Future<void>> calls = <Future<void>>[];
assets.entries.forEach((String fileName, DevFSContent content) {
assets.entries.forEach((String fileName, AssetBundleEntry entry) {
final libfs.File outputFile = globals.fs.file(globals.fs.path.join(assetDir, fileName));
calls.add(writeFile(outputFile, content));
calls.add(writeAssetFile(outputFile, entry));
});
await Future.wait<void>(calls);