envelopeItemStream method

Future<List<int>> envelopeItemStream()

Stream binary data of Envelope item.

Implementation

Future<List<int>> envelopeItemStream() async {
  // Each item needs to be encoded as one unit.
  // Otherwise the header already got yielded if the content throws
  // an exception.
  try {
    final itemHeader = utf8JsonEncoder.convert(await header.toJson());

    final newLine = utf8.encode('\n');
    final data = await dataFactory();
    // TODO the data copy could be avoided - this would be most significant with attachments.
    return [...itemHeader, ...newLine, ...data];
  } catch (e) {
    // TODO rethrow in options.automatedTestMode (currently not available here to check)
    return [];
  }
}