parseJsonFile method
Parses an AST from a JSON file.
Supports both plain .json and gzipped .json.gz files.
Implementation
Future<SCompilationUnit> parseJsonFile(String path) async {
if (!fileExistsSync(path)) {
throw ArgumentD4rtException('AST file not found: $path');
}
List<int> bytes = await readFileAsBytes(path);
// Decompress if gzipped. `package:archive`'s decoder delegates to the
// native dart:io codec on native and to a pure-Dart one on web, so this
// library stays importable from web without changing the bytes read here.
if (path.endsWith('.gz')) {
bytes = const GZipDecoder().decodeBytes(bytes);
}
final jsonString = utf8.decode(bytes);
return parseJson(jsonString);
}