Line data Source code
1 : import 'dart:convert'; 2 : import 'dart:typed_data'; 3 : 4 : /// decodes base64 5 : /// 6 : /// Dart's native [base64.decode()] requires a padded base64 input String. 7 : /// This function allows unpadded base64 too. 8 : /// 9 : /// See: https://github.com/dart-lang/sdk/issues/39510 10 11 : Uint8List base64decodeUnpadded(String s) { 11 44 : final needEquals = (4 - (s.length % 4)) % 4; 12 33 : return base64.decode(s + ('=' * needEquals)); 13 : } 14 : 15 2 : String encodeBase64Unpadded(List<int> s) { 16 6 : return base64Encode(s).replaceAll(RegExp(r'=+$', multiLine: true), ''); 17 : }