mdmerge function

void mdmerge({
  1. required List<String> inputPaths,
  2. required String outputPath,
})

Merges multiple Windows Metadata (.winmd) files into a single output file.

This function reads one or more .winmd files or directories containing .winmd files, expands and parses them into an in-memory metadata index, and writes a merged output .winmd file at the specified outputPath.

Example:

mdmerge(
  inputPaths: ['path/to/directory', 'path/to/file.winmd'],
  outputPath: 'path/to/output/merged.winmd',
);

Implementation

void mdmerge({required List<String> inputPaths, required String outputPath}) {
  if (inputPaths.isEmpty) {
    throw ArgumentError.value(
      inputPaths,
      'inputPaths',
      'At least one input path must be provided.',
    );
  }

  final readers = _expandInput(inputPaths);
  final index = MetadataIndex.fromReaders(readers);
  final writer = MetadataWriter(name: p.basename(outputPath));
  final types = _sortTypes(index.allTypes);
  for (final typeDef in types) {
    _writeType(writer, index, typeDef, null);
  }
  File(outputPath).writeAsBytesSync(writer.toBytes());
}