encode method

  1. @override
String encode()
override

Text encoding of the label and data.

Implementation

@override
String encode() {
  final buf = StringBuffer('$_boundaryBegin$label-----\n'); // pre- boundary

  // Encapsulated text (base64 encode and split into lines)

  final b64 = base64.encode(data);

  var p = 0;
  while (p < b64.length) {
    final endPos = (p + 64 < b64.length) ? (p + 64) : b64.length;
    buf
      ..write(b64.substring(p, endPos))
      ..write('\n');
    p = endPos;
  }

  buf.write('$_boundaryEnd$label-----\n'); // post-encapsulation boundary

  return buf.toString();
}