toBase64Bytes function

Uint8List toBase64Bytes(
  1. List<int> input, {
  2. Base64Codec? codec,
  3. bool url = false,
  4. bool padding = true,
})

Converts 8-bit integer sequence to Base-64 and returns the ASCII bytes.

This is the same as toBase64 but returns the encoded characters as a Uint8List of ASCII codes, skipping the intermediate String.

Parameters:

  • input is a sequence of 8-bit integers
  • If url is true, URL and Filename-safe alphabet is used.
  • If padding is true, the output will have padding characters.
  • codec is the Base64Codec to use. It is derived from the other parameters if not provided.

Implementation

Uint8List toBase64Bytes(
  List<int> input, {
  Base64Codec? codec,
  bool url = false,
  bool padding = true,
}) {
  codec ??= _codecFromParameters(
    url: url,
    padding: padding,
  );
  Uint8List out = codec.encoder.convert(input);
  if (!padding && _codecsWithPadding.contains(codec)) {
    out = Uint8List.fromList(
      out.takeWhile((x) => x != codec!.encoder.padding).toList(),
    );
  }
  return out;
}