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

Side by Side Diff: lib/src/line_decoder.dart

Issue 2833903002: Updated README to notify users of Dart SDK version requirements. (Closed)
Patch Set: Created 3 years, 8 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 | « codereview.settings ('k') | lib/src/sync_http.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) 2017, 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 part of sync.http;
6
7 // '\n' character
8 const int _lineTerminator = 10;
9
10 typedef void _LineDecoderCallback(
11 String line, int bytesRead, _LineDecoder decoder);
12
13 class _LineDecoder {
14 BytesBuilder _unprocessedBytes = new BytesBuilder();
15
16 int expectedByteCount = -1;
17
18 final _LineDecoderCallback _callback;
19
20 _LineDecoder.withCallback(this._callback);
21
22 void add(List<int> chunk) {
23 while (chunk.isNotEmpty) {
24 int splitIndex = -1;
25
26 if (expectedByteCount > 0) {
27 splitIndex = expectedByteCount - _unprocessedBytes.length;
28 } else {
29 splitIndex = chunk.indexOf(_lineTerminator) + 1;
30 }
31
32 if (splitIndex > 0 && splitIndex <= chunk.length) {
33 _unprocessedBytes.add(chunk.sublist(0, splitIndex));
34 chunk = chunk.sublist(splitIndex);
35 expectedByteCount = -1;
36 _process(_unprocessedBytes.takeBytes());
37 } else {
38 _unprocessedBytes.add(chunk);
39 chunk = [];
40 }
41 }
42 }
43
44 void _process(List<int> line) =>
45 _callback(UTF8.decoder.convert(line), line.length, this);
46
47 int get bufferedBytes => _unprocessedBytes.length;
48
49 void close() => _process(_unprocessedBytes.takeBytes());
50 }
OLDNEW
« no previous file with comments | « codereview.settings ('k') | lib/src/sync_http.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698