loadConformanceFixtureAsset function

Future<Uint8List> loadConformanceFixtureAsset(
  1. String indexPath,
  2. ConformanceFixture fixture
)

Loads a fixture relative to its index and verifies declared size and SHA-256.

This VM-only helper reads bytes with dart:io. It throws FormatException when metadata.size or metadata.sha256 is declared and does not match the bytes on disk.

Implementation

Future<Uint8List> loadConformanceFixtureAsset(
  String indexPath,
  ConformanceFixture fixture,
) async {
  final indexUri = await _resolvePackagePath(indexPath);
  final assetUri = indexUri.resolve(fixture.asset);
  final bytes = await File.fromUri(assetUri).readAsBytes();

  final expectedSize = fixture.metadata['size'];
  if (expectedSize != null && expectedSize != bytes.length) {
    throw FormatException(
      'Fixture "${fixture.id}" has size ${bytes.length}, expected '
      '$expectedSize.',
    );
  }

  final expectedHash = fixture.metadata['sha256'];
  if (expectedHash != null) {
    final actualHash = _hex(await HashAlgorithm.sha256.digest(bytes));
    if (expectedHash != actualHash) {
      throw FormatException(
        'Fixture "${fixture.id}" has SHA-256 $actualHash, expected '
        '$expectedHash.',
      );
    }
  }
  return bytes;
}