| 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 * 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 * value (a string), the buffer can be reused between chunks. | 389 * value (a string), the buffer can be reused between chunks. |
| 390 */ | 390 */ |
| 391 Uint8List bufferCache; | 391 Uint8List bufferCache; |
| 392 | 392 |
| 393 _BufferCachingBase64Encoder(bool urlSafe) : super(urlSafe); | 393 _BufferCachingBase64Encoder(bool urlSafe) : super(urlSafe); |
| 394 | 394 |
| 395 Uint8List createBuffer(int bufferLength) { | 395 Uint8List createBuffer(int bufferLength) { |
| 396 if (bufferCache == null || bufferCache.length < bufferLength) { | 396 if (bufferCache == null || bufferCache.length < bufferLength) { |
| 397 bufferCache = new Uint8List(bufferLength); | 397 bufferCache = new Uint8List(bufferLength); |
| 398 } | 398 } |
| 399 // Return a view of the buffer, so it has the reuested length. | 399 // Return a view of the buffer, so it has the requested length. |
| 400 return new Uint8List.view(bufferCache.buffer, 0, bufferLength); | 400 return new Uint8List.view(bufferCache.buffer, 0, bufferLength); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 | 403 |
| 404 abstract class _Base64EncoderSink extends ByteConversionSinkBase { | 404 abstract class _Base64EncoderSink extends ByteConversionSinkBase { |
| 405 void add(List<int> source) { | 405 void add(List<int> source) { |
| 406 _add(source, 0, source.length, false); | 406 _add(source, 0, source.length, false); |
| 407 } | 407 } |
| 408 | 408 |
| 409 void close() { | 409 void close() { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 * contain a full block, the decoded bits (six per character) of the | 535 * contain a full block, the decoded bits (six per character) of the |
| 536 * available characters are stored in [_state] until the next call to | 536 * available characters are stored in [_state] until the next call to |
| 537 * [_decode] or [_close]. | 537 * [_decode] or [_close]. |
| 538 * | 538 * |
| 539 * If no padding has been seen, the value is | 539 * If no padding has been seen, the value is |
| 540 * `numberOfCharactersSeen | (decodedBits << 2)` | 540 * `numberOfCharactersSeen | (decodedBits << 2)` |
| 541 * where `numberOfCharactersSeen` is between 0 and 3 and decoded bits | 541 * where `numberOfCharactersSeen` is between 0 and 3 and decoded bits |
| 542 * contains six bits per seen character. | 542 * contains six bits per seen character. |
| 543 * | 543 * |
| 544 * If padding has been seen the value is negative. It's the bitwise negation | 544 * If padding has been seen the value is negative. It's the bitwise negation |
| 545 * of the number of remanining allowed padding characters (always ~0 or ~1). | 545 * of the number of remaining allowed padding characters (always ~0 or ~1). |
| 546 * | 546 * |
| 547 * A state of `0` or `~0` are valid places to end decoding, all other values | 547 * A state of `0` or `~0` are valid places to end decoding, all other values |
| 548 * mean that a four-character block has not been completed. | 548 * mean that a four-character block has not been completed. |
| 549 */ | 549 */ |
| 550 int _state = 0; | 550 int _state = 0; |
| 551 | 551 |
| 552 /** | 552 /** |
| 553 * Encodes [count] and [bits] as a value to be stored in [_state]. | 553 * Encodes [count] and [bits] as a value to be stored in [_state]. |
| 554 */ | 554 */ |
| 555 static int _encodeCharacterState(int count, int bits) { | 555 static int _encodeCharacterState(int count, int bits) { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 end = RangeError.checkValidRange(start, end, string.length); | 862 end = RangeError.checkValidRange(start, end, string.length); |
| 863 if (start == end) return; | 863 if (start == end) return; |
| 864 Uint8List buffer = _decoder.decode(string, start, end); | 864 Uint8List buffer = _decoder.decode(string, start, end); |
| 865 if (buffer != null) _sink.add(buffer); | 865 if (buffer != null) _sink.add(buffer); |
| 866 if (isLast) { | 866 if (isLast) { |
| 867 _decoder.close(string, end); | 867 _decoder.close(string, end); |
| 868 _sink.close(); | 868 _sink.close(); |
| 869 } | 869 } |
| 870 } | 870 } |
| 871 } | 871 } |
| OLD | NEW |