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

Unified Diff: runtime/bin/stream_util.dart

Issue 8933029: Add pipe to input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments from ager@ Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_stream.dart ('k') | tests/standalone/src/StreamPipeTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/stream_util.dart
diff --git a/runtime/bin/stream_util.dart b/runtime/bin/stream_util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1c9cca3123e394754a7c2fbef3039f0087918946
--- /dev/null
+++ b/runtime/bin/stream_util.dart
@@ -0,0 +1,38 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+void _pipe(InputStream input, OutputStream output, [bool close]) {
+ Function pipeDataHandler;
+ Function pipeCloseHandler;
+ Function pipeNoPendingWriteHandler;
+
+ Function _inputCloseHandler;
+
+ pipeDataHandler = () {
+ List<int> data;
+ while ((data = input.read()) !== null) {
+ if (!output.write(data)) {
+ input.dataHandler = null;
+ output.noPendingWriteHandler = pipeNoPendingWriteHandler;
+ break;
+ }
+ }
+ };
+
+ pipeCloseHandler = () {
+ if (close) output.close();
+ if (_inputCloseHandler !== null) _inputCloseHandler();
+ };
+
+ pipeNoPendingWriteHandler = () {
+ input.dataHandler = pipeDataHandler;
+ output.noPendingWriteHandler = null;
+ };
+
+ _inputCloseHandler = input._clientCloseHandler;
+ input.dataHandler = pipeDataHandler;
+ input.closeHandler = pipeCloseHandler;
+ output.noPendingWriteHandler = null;
+}
+
« no previous file with comments | « runtime/bin/socket_stream.dart ('k') | tests/standalone/src/StreamPipeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698