AstBundle.fromBytes constructor

AstBundle.fromBytes(
  1. List<int> bytes
)

Deserializes a bundle from gzip-compressed JSON bytes.

Throws ArgumentD4rtException if decompression or parsing fails.

Implementation

factory AstBundle.fromBytes(List<int> bytes) {
  try {
    final decompressed = gzip.decode(bytes);
    final jsonString = utf8.decode(decompressed);
    final json = jsonDecode(jsonString);
    if (json is! Map<String, dynamic>) {
      throw ArgumentD4rtException(
        'Invalid bundle bytes: decoded JSON is not an object',
      );
    }
    return AstBundle.fromJson(json);
  } on FormatException catch (e) {
    throw ArgumentD4rtException('Invalid bundle bytes: ${e.message}');
  }
}