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

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

Issue 1777643003: Uses a finalizer to delete zlib filter resources (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments. Fix more problems. 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
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 if (_empty) _filter.process(const [], 0, 0); 511 if (_empty) _filter.process(const [], 0, 0);
512 try { 512 try {
513 var out; 513 var out;
514 while ((out = _filter.processed(end: true)) != null) { 514 while ((out = _filter.processed(end: true)) != null) {
515 _sink.add(out); 515 _sink.add(out);
516 } 516 }
517 } catch (e) { 517 } catch (e) {
518 _closed = true; 518 _closed = true;
519 throw e; 519 throw e;
520 } 520 }
521 if (!_closed) _filter.end();
522 _closed = true; 521 _closed = true;
523 _sink.close(); 522 _sink.close();
524 } 523 }
525 } 524 }
526 525
527 526
528 /** 527 /**
529 * Private helper-class to handle native filters. 528 * Private helper-class to handle native filters.
530 */ 529 */
531 abstract class _Filter { 530 abstract class _Filter {
532 /** 531 /**
533 * Call to process a chunk of data. A call to [process] should only be made 532 * Call to process a chunk of data. A call to [process] should only be made
534 * when [processed] returns [:null:]. 533 * when [processed] returns [:null:].
535 */ 534 */
536 void process(List<int> data, int start, int end); 535 void process(List<int> data, int start, int end);
537 536
538 /** 537 /**
539 * Get a chunk of processed data. When there are no more data available, 538 * Get a chunk of processed data. When there are no more data available,
540 * [processed] will return [:null:]. Set [flush] to [:false:] for non-final 539 * [processed] will return [:null:]. Set [flush] to [:false:] for non-final
541 * calls to improve performance of some filters. 540 * calls to improve performance of some filters.
542 * 541 *
543 * The last call to [processed] should have [end] set to [:true:]. This will 542 * The last call to [processed] should have [end] set to [:true:]. This will
544 * make sure an 'end' packet is written on the stream. 543 * make sure an 'end' packet is written on the stream.
545 */ 544 */
546 List<int> processed({bool flush: true, bool end: false}); 545 List<int> processed({bool flush: true, bool end: false});
547 546
548 /**
549 * Mark the filter as closed. Always call this method for any filter created
550 * to avoid leaking resources. [end] can be called at any time, but any
551 * successive calls to [process] or [processed] will fail.
552 */
553 void end();
554
555 external static _Filter _newZLibDeflateFilter(bool gzip, int level, 547 external static _Filter _newZLibDeflateFilter(bool gzip, int level,
556 int windowBits, int memLevel, 548 int windowBits, int memLevel,
557 int strategy, 549 int strategy,
558 List<int> dictionary, bool raw); 550 List<int> dictionary, bool raw);
559 551
560 external static _Filter _newZLibInflateFilter(int windowBits, 552 external static _Filter _newZLibInflateFilter(int windowBits,
561 List<int> dictionary, bool raw); 553 List<int> dictionary, bool raw);
562 } 554 }
563 555
564 void _validateZLibWindowBits(int windowBits) { 556 void _validateZLibWindowBits(int windowBits) {
(...skipping 21 matching lines...) Expand all
586 } 578 }
587 579
588 void _validateZLibStrategy(int strategy) { 580 void _validateZLibStrategy(int strategy) {
589 const strategies = const <int>[ZLibOption.STRATEGY_FILTERED, 581 const strategies = const <int>[ZLibOption.STRATEGY_FILTERED,
590 ZLibOption.STRATEGY_HUFFMAN_ONLY, ZLibOption.STRATEGY_RLE, 582 ZLibOption.STRATEGY_HUFFMAN_ONLY, ZLibOption.STRATEGY_RLE,
591 ZLibOption.STRATEGY_FIXED, ZLibOption.STRATEGY_DEFAULT]; 583 ZLibOption.STRATEGY_FIXED, ZLibOption.STRATEGY_DEFAULT];
592 if (strategies.indexOf(strategy) == -1) { 584 if (strategies.indexOf(strategy) == -1) {
593 throw new ArgumentError("Unsupported 'strategy'"); 585 throw new ArgumentError("Unsupported 'strategy'");
594 } 586 }
595 } 587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698