inspect method
NativeBinaryInfo
inspect(
- File file, {
- required NativeTarget target,
- required String canonicalName,
Inspects a file and returns validation results.
Throws BinaryFormatException if the file does not match the expected format, or BinaryArchitectureException if the architecture is wrong.
Implementation
NativeBinaryInfo inspect(
File file, {
required NativeTarget target,
required String canonicalName,
}) {
if (!file.existsSync()) {
throw BinaryFormatException('File not found: ${file.path}');
}
final raf = file.openSync();
List<int> header;
try {
header = raf.readSync(32);
} finally {
raf.closeSync();
}
if (header.isEmpty) {
throw BinaryFormatException('Empty file: ${file.path}');
}
final format = _detectFormat(canonicalName, header);
if (validateArchitecture && format != _BinaryFormat.staticArchive) {
_validateArchitecture(header, format, target, file.path);
}
return NativeBinaryInfo(
path: file.path,
format: format,
sizeBytes: file.lengthSync(),
);
}