encode static method Null safety

String encode(
  1. List<int> bytes,
  2. [int lineSize = 0,
  3. String? linePadding]
)

Implementation

static String encode(List<int> bytes,
    [int lineSize = 0, String? linePadding]) {
  List<int?> charCodes = encodeToCharCode(bytes);
  if (lineSize <= 0) {
    return new String.fromCharCodes(charCodes as Iterable<int>);
  }
  List rslt = [];
  int len = charCodes.length;
  for (int i = 0; i < len; i += lineSize) {
    int j = i + lineSize;
    if (j < len) {
      j = len;
    }
    if (linePadding != null) {
      rslt.add(
          '$linePadding${new String.fromCharCodes(charCodes.sublist(i, j) as Iterable<int>)}');
    } else {
      rslt.add(
          new String.fromCharCodes(charCodes.sublist(i, j) as Iterable<int>));
    }
  }
  return rslt.join('\n');
}