toBase64 function

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

Converts 8-bit integer sequence to 6-bit Base-64 character sequence.

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

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