padBytesLeft static method

BuBytes padBytesLeft(
  1. List<int> bytes,
  2. int length
)

Left-pads bytes with zeros to length bytes. If bytes is already length bytes or longer, a copy is returned.

Implementation

static BuBytes padBytesLeft(List<int> bytes, int length) {
  if (bytes.length >= length) {
    return BuBytes(bytes);
  }

  final result = List<int>.filled(length, 0);
  final start = length - bytes.length;
  result.setRange(start, length, bytes);

  return BuBytes(result);
}