envelopeStream method

Stream<List<int>> envelopeStream(
  1. SentryOptions options
)

Stream binary data representation of Envelope file encoded.

Implementation

Stream<List<int>> envelopeStream(SentryOptions options) async* {
  yield utf8JsonEncoder.convert(header.toJson());

  final newLineData = utf8.encode('\n');
  for (final item in items) {
    try {
      final dataFuture = item.dataFactory();
      final data = dataFuture is Future ? await dataFuture : dataFuture;

      // Only attachments should be filtered according to
      // SentryOptions.maxAttachmentSize
      if (item.header.type == SentryItemType.attachment &&
          data.length > options.maxAttachmentSize) {
        continue;
      }

      yield newLineData;
      yield utf8JsonEncoder.convert(await item.header.toJson(data.length));
      yield newLineData;
      yield data;
    } catch (_) {
      if (options.automatedTestMode) {
        rethrow;
      }
      // Skip throwing envelope item data closure.
      continue;
    }
  }
}