transferToLength method

List<int> transferToLength(
  1. List<int> bytes, {
  2. int? byteLength,
})

Convert bytes to bytes of specified length

  • bytes
  • byteLengthOptional

Implementation

List<int> transferToLength(List<int> bytes, {int? byteLength}) {
  if (byteLength == null) return bytes;
  final List<int> ret = List.from(bytes);
  if (bytes.length <= byteLength) {
    ret.addAll(List.filled(byteLength - bytes.length, 0x00));
    return ret;
  } else {
    ret.removeRange(byteLength, bytes.length);
    return ret;
  }
}