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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 String convert(List<int> input) { | 59 String convert(List<int> input) { |
60 if (input.isEmpty) return ""; | 60 if (input.isEmpty) return ""; |
61 var encoder = new _Base64Encoder(); | 61 var encoder = new _Base64Encoder(); |
62 Uint8List buffer = encoder.encode(input, 0, input.length, true); | 62 Uint8List buffer = encoder.encode(input, 0, input.length, true); |
63 return new String.fromCharCodes(buffer); | 63 return new String.fromCharCodes(buffer); |
64 } | 64 } |
65 | 65 |
66 ByteConversionSink startChunkedConversion(Sink<String> sink) { | 66 ByteConversionSink startChunkedConversion(Sink<String> sink) { |
67 if (sink is StringConversionSink) { | 67 if (sink is StringConversionSink) { |
68 return new _Utf8Base64EncoderSink(sink.asUtf8Sink()); | 68 return new _Utf8Base64EncoderSink(sink.asUtf8Sink(false)); |
69 } | 69 } |
70 return new _AsciiBase64EncoderSink(sink); | 70 return new _AsciiBase64EncoderSink(sink); |
71 } | 71 } |
72 | 72 |
73 Stream<String> bind(Stream<List<int>> stream) { | 73 Stream<String> bind(Stream<List<int>> stream) { |
74 return new Stream<String>.eventTransformed( | 74 return new Stream<String>.eventTransformed( |
75 stream, | 75 stream, |
76 (EventSink sink) => | 76 (EventSink sink) => |
77 new _ConverterStreamEventSink<List<int>, String>(this, sink)); | 77 new _ConverterStreamEventSink<List<int>, String>(this, sink)); |
78 } | 78 } |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 * That means zero or one padding character (depending on [_state]) | 568 * That means zero or one padding character (depending on [_state]) |
569 * and nothing else. | 569 * and nothing else. |
570 */ | 570 */ |
571 static int _checkPadding(String input, int start, int end, int state) { | 571 static int _checkPadding(String input, int start, int end, int state) { |
572 assert(_hasSeenPadding(state)); | 572 assert(_hasSeenPadding(state)); |
573 if (start == end) return state; | 573 if (start == end) return state; |
574 int expectedPadding = _statePadding(state); | 574 int expectedPadding = _statePadding(state); |
575 if (expectedPadding > 0) { | 575 if (expectedPadding > 0) { |
576 int firstChar = input.codeUnitAt(start); | 576 int firstChar = input.codeUnitAt(start); |
577 if (firstChar != _paddingChar) { | 577 if (firstChar != _paddingChar) { |
578 throw new FormatException("Missing padding character", string, start); | 578 throw new FormatException("Missing padding character", input, start); |
579 } | 579 } |
580 state = _encodePaddingState(0); | 580 state = _encodePaddingState(0); |
581 start++; | 581 start++; |
582 } | 582 } |
583 if (start != end) { | 583 if (start != end) { |
584 throw new FormatException("Invalid character after padding", | 584 throw new FormatException("Invalid character after padding", |
585 input, start); | 585 input, start); |
586 } | 586 } |
587 return state; | 587 return state; |
588 } | 588 } |
(...skipping 21 matching lines...) Expand all Loading... |
610 end = RangeError.checkValidRange(start, end, string.length); | 610 end = RangeError.checkValidRange(start, end, string.length); |
611 if (start == end) return; | 611 if (start == end) return; |
612 Uint8List buffer = _decoder.decode(string, start, end); | 612 Uint8List buffer = _decoder.decode(string, start, end); |
613 if (buffer != null) _sink.add(buffer); | 613 if (buffer != null) _sink.add(buffer); |
614 if (isLast) { | 614 if (isLast) { |
615 _decoder.close(string, end); | 615 _decoder.close(string, end); |
616 _sink.close(); | 616 _sink.close(); |
617 } | 617 } |
618 } | 618 } |
619 } | 619 } |
OLD | NEW |