OLD | NEW |
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 Loading... |
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, [int start = 0, int end]) { | 310 List<int> convert(String input) { |
311 end = RangeError.checkValidRange(start, end, input.length); | 311 if (input.isEmpty) return new Uint8List(0); |
312 if (start == end) return new Uint8List(0); | 312 int length = input.length; |
313 var decoder = new _Base64Decoder(); | 313 var decoder = new _Base64Decoder(); |
314 Uint8List buffer = decoder.decode(input, start, end); | 314 Uint8List buffer = decoder.decode(input, 0, input.length); |
315 decoder.close(input, end); | 315 decoder.close(input, input.length); |
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 Loading... |
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 } |
OLD | NEW |