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

Side by Side Diff: lib/src/base64/encoder_sink.dart

Issue 1819293003: Remove deprecated APIs. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: Created 4 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
« no previous file with comments | « lib/src/base64/encoder.dart ('k') | lib/src/crypto_utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:convert';
6
7 import 'encoder.dart';
8
9 /// This is deprecated.
10 ///
11 /// Use the `Base64Encoder` class in `dart:convert` instead.
12 @Deprecated("Will be removed in crypto 1.0.0.")
13 class Base64EncoderSink extends ChunkedConversionSink<List<int>> {
14 /// The encoder used to encode each chunk.
15 final Base64Encoder _encoder;
16
17 /// The underlying sink to which to emit the encoded strings.
18 final ChunkedConversionSink<String> _outSink;
19
20 /// The buffer of as-yet-unconverted bytes.
21 ///
22 /// This is used to ensure that we don't generate interstitial padding
23 /// characters.
24 final _buffer = new List<int>();
25
26 /// The length of [_buffer]; that is, the number of unconverted bytes.
27 var _bufferCount = 0;
28
29 Base64EncoderSink(this._outSink, urlSafe, addLineSeparator)
30 : _encoder = new Base64Encoder(
31 urlSafe: urlSafe, addLineSeparator: addLineSeparator);
32
33 void add(List<int> chunk) {
34 var nextBufferCount = (chunk.length + _bufferCount) % 3;
35 var decodableLength = _bufferCount + chunk.length - nextBufferCount;
36
37 if (_bufferCount + chunk.length > _buffer.length) {
38 _buffer.replaceRange(_bufferCount, _buffer.length,
39 chunk.sublist(0, _buffer.length - _bufferCount));
40 _buffer.addAll(chunk.sublist(_buffer.length - _bufferCount));
41 } else {
42 _buffer.replaceRange(_bufferCount, _bufferCount + chunk.length, chunk);
43 }
44
45 _outSink.add(_encoder.convert(_buffer, 0, decodableLength));
46 _buffer.removeRange(0, decodableLength);
47 _bufferCount = nextBufferCount;
48 }
49
50 void close() {
51 if (_bufferCount > 0) {
52 _outSink.add(_encoder.convert(_buffer.sublist(0, _bufferCount)));
53 }
54 _outSink.close();
55 }
56 }
57
OLDNEW
« no previous file with comments | « lib/src/base64/encoder.dart ('k') | lib/src/crypto_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698