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) {
    final length = await item.header.length();
    // A length smaller than 0 indicates an invalid envelope, which should not
    // be send to Sentry.io
    if (length < 0) {
      continue;
    }
    // Only attachments should be filtered according to
    // SentryOptions.maxAttachmentSize
    if (item.header.type == SentryItemType.attachment) {
      if (await item.header.length() > options.maxAttachmentSize) {
        continue;
      }
    }
    final itemStream = await item.envelopeItemStream();
    if (itemStream.isNotEmpty) {
      yield newLineData;
      yield itemStream;
    }
  }
}