decodeFromBuffer method

Future<MovieEntity> decodeFromBuffer(
  1. List<int> bytes
)

Implementation

Future<MovieEntity> decodeFromBuffer(List<int> bytes) async {
  if (maxInputBytes <= 0 ||
      maxInflatedBytes <= 0 ||
      maxImagePixels <= 0 ||
      maxDecodedImageBytes <= 0) {
    throw ArgumentError('Resource limits must be positive');
  }
  if (bytes.length > maxInputBytes) {
    throw StateError('SVGA input is too large');
  }
  TimelineTask? timeline;
  if (!kReleaseMode) {
    timeline = TimelineTask(filterKey: _filterKey)
      ..start('DecodeFromBuffer', arguments: {'length': bytes.length});
  }
  MovieEntity? movie;
  try {
    // Native platforms inflate and parse away from the rendering isolate.
    // Flutter compute runs on the current event loop on Web.
    final parsed = await compute<(Uint8List, int), MovieEntity>(_parseMovie, (
      Uint8List.fromList(bytes),
      maxInflatedBytes,
    ));
    movie = parsed;
    await _prepareResources(parsed, timeline: timeline);
    if (!retainSourceImages) parsed.images.clear();
    return parsed;
  } catch (_) {
    movie?.dispose();
    rethrow;
  } finally {
    timeline?.finish();
  }
}