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

Side by Side Diff: sdk/lib/convert/chunked_conversion.dart

Issue 19883003: Add chunked conversion to converters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/convert/byte_conversion.dart ('k') | sdk/lib/convert/convert.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) 2013, 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 dart.convert;
6
7 typedef void _ChunkedConversionCallback<T>(T accumulated);
8
9 /**
10 * A [ChunkedConversionSink] is used to transmit data more efficiently between
11 * two converters during chunked conversions.
12 */
13 abstract class ChunkedConversionSink<T> {
14 ChunkedConversionSink();
15 factory ChunkedConversionSink.withCallback(
16 void callback(List<T> accumulated)) = _SimpleCallbackSink;
17
18 /**
19 * Adds chunked data to this sink.
20 *
21 * This method is also used when converters are used as [StreamTransformer]s.
22 */
23 void add(T chunk);
24
25 /**
26 * Closes the sink.
27 *
28 * This signals the end of the chunked conversion. This method is called
29 * when converters are used as [StreamTransformer]'s.
30 */
31 void close();
32 }
33
34 /**
35 * This class accumulates all chunks and invokes a callback with a list of
36 * the chunks when the sink is closed.
37 *
38 * This class can be used to terminate a chunked conversion.
39 */
40 class _SimpleCallbackSink<T> extends ChunkedConversionSink<T> {
41 final _ChunkedConversionCallback<List<T>> _callback;
42 final List<T> _accumulated = <T>[];
43
44 _SimpleCallbackSink(this._callback);
45
46 void add(T chunk) { _accumulated.add(chunk); }
47 void close() { _callback(_accumulated); }
48 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/byte_conversion.dart ('k') | sdk/lib/convert/convert.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698