List _convert()

in lib/src/chunked_coding/encoder.dart [60:83]


List<int> _convert(List<int> bytes, int start, int end, {bool isLast = false}) {
  if (end == start) return isLast ? _doneChunk : const [];

  final size = end - start;
  final sizeInHex = size.toRadixString(16);
  final footerSize = isLast ? _doneChunk.length : 0;

  // Add 4 for the CRLF sequences that follow the size header and the bytes.
  final list = Uint8List(sizeInHex.length + 4 + size + footerSize);
  list.setRange(0, sizeInHex.length, sizeInHex.codeUnits);

  var cursor = sizeInHex.length;
  list[cursor++] = $cr;
  list[cursor++] = $lf;
  list.setRange(cursor, cursor + end - start, bytes, start);
  cursor += end - start;
  list[cursor++] = $cr;
  list[cursor++] = $lf;

  if (isLast) {
    list.setRange(list.length - footerSize, list.length, _doneChunk);
  }
  return list;
}