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

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

Issue 1381033002: Add data-URI support class to dart:core (next to Uri). (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove VM assertion that appears to be incorrect. Created 5 years, 1 month 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 * An instance of [Base64Codec]. 8 * An instance of [Base64Codec].
9 * 9 *
10 * This instance provides a convenient access to 10 * This instance provides a convenient access to
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 } 301 }
302 302
303 // ------------------------------------------------------------------------ 303 // ------------------------------------------------------------------------
304 // Decoder 304 // Decoder
305 // ------------------------------------------------------------------------ 305 // ------------------------------------------------------------------------
306 306
307 class Base64Decoder extends Converter<String, List<int>> { 307 class Base64Decoder extends Converter<String, List<int>> {
308 const Base64Decoder(); 308 const Base64Decoder();
309 309
310 List<int> convert(String input) { 310 List<int> convert(String input, [int start = 0, int end]) {
311 if (input.isEmpty) return new Uint8List(0); 311 end = RangeError.checkValidRange(start, end, input.length);
312 int length = input.length; 312 if (start == end) return new Uint8List(0);
313 var decoder = new _Base64Decoder(); 313 var decoder = new _Base64Decoder();
314 Uint8List buffer = decoder.decode(input, 0, input.length); 314 Uint8List buffer = decoder.decode(input, start, end);
315 decoder.close(input, input.length); 315 decoder.close(input, end);
316 return buffer; 316 return buffer;
317 } 317 }
318 318
319 StringConversionSink startChunkedConversion(Sink<List<int>> sink) { 319 StringConversionSink startChunkedConversion(Sink<List<int>> sink) {
320 return new _Base64DecoderSink(sink); 320 return new _Base64DecoderSink(sink);
321 } 321 }
322 } 322 }
323 323
324 /** 324 /**
325 * Helper class implementing base64 decoding with intermediate state. 325 * Helper class implementing base64 decoding with intermediate state.
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 end = RangeError.checkValidRange(start, end, string.length); 704 end = RangeError.checkValidRange(start, end, string.length);
705 if (start == end) return; 705 if (start == end) return;
706 Uint8List buffer = _decoder.decode(string, start, end); 706 Uint8List buffer = _decoder.decode(string, start, end);
707 if (buffer != null) _sink.add(buffer); 707 if (buffer != null) _sink.add(buffer);
708 if (isLast) { 708 if (isLast) {
709 _decoder.close(string, end); 709 _decoder.close(string, end);
710 _sink.close(); 710 _sink.close();
711 } 711 }
712 } 712 }
713 } 713 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698