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

Side by Side Diff: sdk/lib/io/data_transformer.dart

Issue 203603008: Introduce class Sink<T>. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/sink.dart ('k') | sdk/lib/io/string_transformer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * Exposes ZLib options for input parameters. 8 * Exposes ZLib options for input parameters.
9 * 9 *
10 * See http://www.zlib.net/manual.html for more documentation. 10 * See http://www.zlib.net/manual.html for more documentation.
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 * constructor. 355 * constructor.
356 */ 356 */
357 List<int> convert(List<int> bytes) { 357 List<int> convert(List<int> bytes) {
358 _BufferSink sink = new _BufferSink(); 358 _BufferSink sink = new _BufferSink();
359 startChunkedConversion(sink)..add(bytes)..close(); 359 startChunkedConversion(sink)..add(bytes)..close();
360 return sink.builder.takeBytes(); 360 return sink.builder.takeBytes();
361 } 361 }
362 362
363 /** 363 /**
364 * Start a chunked conversion using the options given to the [ZLibEncoder] 364 * Start a chunked conversion using the options given to the [ZLibEncoder]
365 * constructor. While it accepts any [ChunkedConversionSink] taking 365 * constructor. While it accepts any [Sink] taking [List<int>]'s,
366 * [List<int>]'s, the optimal sink to be passed as [sink] is a 366 * the optimal sink to be passed as [sink] is a [ByteConversionSink].
367 * [ByteConversionSink].
368 */ 367 */
369 ByteConversionSink startChunkedConversion( 368 ByteConversionSink startChunkedConversion(Sink<List<int>> sink) {
370 ChunkedConversionSink<List<int>> sink) {
371 if (sink is! ByteConversionSink) { 369 if (sink is! ByteConversionSink) {
372 sink = new ByteConversionSink.from(sink); 370 sink = new ByteConversionSink.from(sink);
373 } 371 }
374
375 return new _ZLibEncoderSink(sink, gzip, level, windowBits, memLevel, 372 return new _ZLibEncoderSink(sink, gzip, level, windowBits, memLevel,
376 strategy, dictionary, raw); 373 strategy, dictionary, raw);
377 } 374 }
378 } 375 }
379 376
380 377
381 /** 378 /**
382 * The [ZLibDecoder] is used by [ZLibCodec] and [GZipCodec] to decompress data. 379 * The [ZLibDecoder] is used by [ZLibCodec] and [GZipCodec] to decompress data.
383 */ 380 */
384 class ZLibDecoder extends Converter<List<int>, List<int>> { 381 class ZLibDecoder extends Converter<List<int>, List<int>> {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 * Convert a list of bytes using the options given to the [ZLibDecoder] 413 * Convert a list of bytes using the options given to the [ZLibDecoder]
417 * constructor. 414 * constructor.
418 */ 415 */
419 List<int> convert(List<int> bytes) { 416 List<int> convert(List<int> bytes) {
420 _BufferSink sink = new _BufferSink(); 417 _BufferSink sink = new _BufferSink();
421 startChunkedConversion(sink)..add(bytes)..close(); 418 startChunkedConversion(sink)..add(bytes)..close();
422 return sink.builder.takeBytes(); 419 return sink.builder.takeBytes();
423 } 420 }
424 421
425 /** 422 /**
426 * Start a chunked conversion. While it accepts any [ChunkedConversionSink] 423 * Start a chunked conversion. While it accepts any [Sink]
427 * taking [List<int>]'s, the optimal sink to be passed as [sink] is a 424 * taking [List<int>]'s, the optimal sink to be passed as [sink] is a
428 * [ByteConversionSink]. 425 * [ByteConversionSink].
429 */ 426 */
430 ByteConversionSink startChunkedConversion( 427 ByteConversionSink startChunkedConversion(Sink<List<int>> sink) {
431 ChunkedConversionSink<List<int>> sink) {
432 if (sink is! ByteConversionSink) { 428 if (sink is! ByteConversionSink) {
433 sink = new ByteConversionSink.from(sink); 429 sink = new ByteConversionSink.from(sink);
434 } 430 }
435 return new _ZLibDecoderSink(sink, windowBits, dictionary, raw); 431 return new _ZLibDecoderSink(sink, windowBits, dictionary, raw);
436 } 432 }
437 } 433 }
438 434
439 435
440 class _BufferSink extends ByteConversionSink { 436 class _BufferSink extends ByteConversionSink {
441 final BytesBuilder builder = new BytesBuilder(); 437 final BytesBuilder builder = new BytesBuilder();
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 586 }
591 587
592 void _validateZLibStrategy(int strategy) { 588 void _validateZLibStrategy(int strategy) {
593 const strategies = const <int>[ZLibOption.STRATEGY_FILTERED, 589 const strategies = const <int>[ZLibOption.STRATEGY_FILTERED,
594 ZLibOption.STRATEGY_HUFFMAN_ONLY, ZLibOption.STRATEGY_RLE, 590 ZLibOption.STRATEGY_HUFFMAN_ONLY, ZLibOption.STRATEGY_RLE,
595 ZLibOption.STRATEGY_FIXED, ZLibOption.STRATEGY_DEFAULT]; 591 ZLibOption.STRATEGY_FIXED, ZLibOption.STRATEGY_DEFAULT];
596 if (strategies.indexOf(strategy) == -1) { 592 if (strategies.indexOf(strategy) == -1) {
597 throw new ArgumentError("Unsupported 'strategy'"); 593 throw new ArgumentError("Unsupported 'strategy'");
598 } 594 }
599 } 595 }
OLDNEW
« no previous file with comments | « sdk/lib/core/sink.dart ('k') | sdk/lib/io/string_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698