encode method

  1. @override
String encode()
override

Encode as text.

Produced the single-line representation.

The optional comment is included only if its has a value and that value is not a blank or empty string.

Implementation

@override
String encode() {
  // Key-type is the same as the first chunk

  final keyType = BinaryRange(data).nextString();

  // Only include the comment if its value is not empty.

  var spacePlusComment = '';

  if (comment != null) {
    // There is a comment.
    // Note: all spaces in the comment are preserved.
    var s = comment!;
    s = s.replaceAll('\r', ' '); // disallow multi-line comments
    s = s.replaceAll('\n', ' ');

    if (s.isNotEmpty) {
      spacePlusComment = ' $s'; // add a space in front of the comment
    }
  }

  // Produce the one-line encoding

  return '$keyType ${base64.encode(data)}$spacePlusComment\n';
}