Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(856)

Side by Side Diff: sdk/lib/convert/base64.dart

Issue 2764943002: Fix some strong mode issues in the core libraries. (Closed)
Patch Set: Fix another type issue. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * A [base64](https://tools.ietf.org/html/rfc4648) encoder and decoder. 8 * A [base64](https://tools.ietf.org/html/rfc4648) encoder and decoder.
9 * 9 *
10 * It encodes using the default base64 alphabet, 10 * It encodes using the default base64 alphabet,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Encoder 197 // Encoder
198 // ------------------------------------------------------------------------ 198 // ------------------------------------------------------------------------
199 199
200 /** 200 /**
201 * Base64 and base64url encoding converter. 201 * Base64 and base64url encoding converter.
202 * 202 *
203 * Encodes lists of bytes using base64 or base64url encoding. 203 * Encodes lists of bytes using base64 or base64url encoding.
204 * 204 *
205 * The results are ASCII strings using a restricted alphabet. 205 * The results are ASCII strings using a restricted alphabet.
206 */ 206 */
207 class Base64Encoder extends Converter<List<int>, String> 207 class Base64Encoder extends Converter<List<int>, String> {
208 implements ChunkedConverter<List<int>, String, List<int>, String> {
209 208
210 final bool _urlSafe; 209 final bool _urlSafe;
211 210
212 const Base64Encoder() : _urlSafe = false; 211 const Base64Encoder() : _urlSafe = false;
213 const Base64Encoder.urlSafe() : _urlSafe = true; 212 const Base64Encoder.urlSafe() : _urlSafe = true;
214 213
215 String convert(List<int> input) { 214 String convert(List<int> input) {
216 if (input.isEmpty) return ""; 215 if (input.isEmpty) return "";
217 var encoder = new _Base64Encoder(_urlSafe); 216 var encoder = new _Base64Encoder(_urlSafe);
218 Uint8List buffer = encoder.encode(input, 0, input.length, true); 217 Uint8List buffer = encoder.encode(input, 0, input.length, true);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 // Decoder 468 // Decoder
470 // ------------------------------------------------------------------------ 469 // ------------------------------------------------------------------------
471 470
472 /** 471 /**
473 * Decoder for base64 encoded data. 472 * Decoder for base64 encoded data.
474 * 473 *
475 * This decoder accepts both base64 and base64url ("url-safe") encodings. 474 * This decoder accepts both base64 and base64url ("url-safe") encodings.
476 * 475 *
477 * The encoding is required to be properly padded. 476 * The encoding is required to be properly padded.
478 */ 477 */
479 class Base64Decoder extends Converter<String, List<int>> 478 class Base64Decoder extends Converter<String, List<int>> {
480 implements ChunkedConverter<String, List<int>, String, List<int>> {
481 479
482 const Base64Decoder(); 480 const Base64Decoder();
483 481
484 List<int> convert(String input, [int start = 0, int end]) { 482 List<int> convert(String input, [int start = 0, int end]) {
485 end = RangeError.checkValidRange(start, end, input.length); 483 end = RangeError.checkValidRange(start, end, input.length);
486 if (start == end) return new Uint8List(0); 484 if (start == end) return new Uint8List(0);
487 var decoder = new _Base64Decoder(); 485 var decoder = new _Base64Decoder();
488 Uint8List buffer = decoder.decode(input, start, end); 486 Uint8List buffer = decoder.decode(input, start, end);
489 decoder.close(input, end); 487 decoder.close(input, end);
490 return buffer; 488 return buffer;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 end = RangeError.checkValidRange(start, end, string.length); 876 end = RangeError.checkValidRange(start, end, string.length);
879 if (start == end) return; 877 if (start == end) return;
880 Uint8List buffer = _decoder.decode(string, start, end); 878 Uint8List buffer = _decoder.decode(string, start, end);
881 if (buffer != null) _sink.add(buffer); 879 if (buffer != null) _sink.add(buffer);
882 if (isLast) { 880 if (isLast) {
883 _decoder.close(string, end); 881 _decoder.close(string, end);
884 _sink.close(); 882 _sink.close();
885 } 883 }
886 } 884 }
887 } 885 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698