Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Input is read from a given input stream. Such an input stream can | 6 * Input is read from a given input stream. Such an input stream can |
| 7 * be an endpoint, e.g., a socket or a file, or another input stream. | 7 * be an endpoint, e.g., a socket or a file, or another input stream. |
| 8 * Multiple input streams can be chained together to operate collaboratively | 8 * Multiple input streams can be chained together to operate collaboratively |
|
rchandia
2011/10/17 21:53:46
This does not seem to allow chaining.
Søren Gjesse
2011/10/18 15:23:20
Chaining is now use for StringInputStream.
| |
| 9 * on a given input. | 9 * on a given input. |
| 10 */ | 10 */ |
| 11 interface InputStream { | 11 interface InputStream { |
|
dcarlson
2011/10/17 21:05:20
Is there a reason to not have a way to just regist
Søren Gjesse
2011/10/18 15:23:20
I think it will make sense to have a way of regist
| |
| 12 /** | 12 /** |
| 13 * Reads [len] bytes into [buffer] buffer starting at [offset] offset. | 13 * Reads [len] bytes from the stream. When the bytes have been read the |
| 14 * [callback] callback is invoked on completion unless it is null. | 14 * specified [callback] is called with the data. |
|
dcarlson
2011/10/17 21:05:20
Address EOF case.
Søren Gjesse
2011/10/18 15:23:20
The current handling of EOF is that if [len] chara
| |
| 15 */ | 15 void readFully(int len, void callback(List<int> buffer)); |
|
dcarlson
2011/10/17 21:05:20
Seems like this is the most common case -- perhaps
Søren Gjesse
2011/10/18 15:23:20
I have not tried to split the stream interface and
| |
| 16 bool read(List<int> buffer, int offset, int len, void callback()); | |
| 17 | 16 |
| 18 /** | 17 /** |
| 19 * Reads data from the stream into a buffer until a given [pattern] occurs and | 18 * Reads data from the stream into a buffer until the specified [pattern] |
|
rchandia
2011/10/17 21:53:46
When I hear pattern I think RegEx'es which is not
Søren Gjesse
2011/10/18 15:23:20
Currently it is simple string matching.
| |
| 20 * hands that buffer over as an input to the registered [callback]. | 19 * occurs. When the pattern occours the specified [callback] is called with |
| 21 * The callback is not invoked if a read error occurs. | 20 * the data including the pattern. If the pattern is not found before |
| 21 * [maxLength] bytes have been received the error handler will be called. | |
|
rchandia
2011/10/17 21:53:46
How can errorHandler recover?
Søren Gjesse
2011/10/18 15:23:20
Currently not known.
| |
| 22 */ | 22 */ |
|
dcarlson
2011/10/17 21:05:20
Also: clarify what happens when you hit EOF prior
Søren Gjesse
2011/10/18 15:23:20
Currently there will be not callback if EOF is hit
| |
| 23 void readUntil(List<int> pattern, void callback(List<int> buffer)); | 23 void readUntil(List<int> pattern, |
| 24 void callback(List<int> buffer), | |
| 25 [int maxLength = -1]); | |
| 26 | |
| 27 /** | |
| 28 * Reads as much data as is available from the stream. If no data is | |
| 29 * available null will be returned and the specified callback will | |
| 30 * be called when data becomes available. | |
|
rchandia
2011/10/17 21:53:46
What happens when readFully() is followed by read(
Søren Gjesse
2011/10/18 15:23:20
It is a problem with these different functions on
| |
| 31 */ | |
| 32 List<int> read(void callback()); | |
|
dcarlson
2011/10/17 21:05:20
make callback optional named param?
Søren Gjesse
2011/10/18 15:23:20
Removed the callback in favor the dataHandler.
| |
| 33 | |
| 34 /** | |
| 35 * Close the stream. This will normally also close the underlying | |
|
rchandia
2011/10/17 21:53:46
Does this prevent further reads?
Søren Gjesse
2011/10/18 15:23:20
We should make it possible to read all data after
| |
| 36 * communication channel. | |
| 37 */ | |
| 38 void close(); | |
| 39 | |
| 40 /** | |
| 41 * The close handler gets called when the underlying communication | |
| 42 * channel gets closed. Not all types of communication channels will | |
| 43 * emit close events. | |
| 44 */ | |
| 45 void set closeHandler(void callback()); | |
| 46 | |
| 47 /** | |
| 48 * The error handler gets called when the underlying communication | |
| 49 * channel gets into some kind of error situation. | |
| 50 */ | |
| 51 void set errorHandler(void callback(StreamError error)); | |
| 24 } | 52 } |
| 53 | |
| 54 interface StringInputStream extends InputStream { | |
| 55 /** | |
| 56 * Reads [len] characters from the stream. When the bytes have been read the | |
| 57 * specified [callback] is called with the data. | |
| 58 void readFully(int len, void callback(String data)); | |
| 59 | |
| 60 /** | |
| 61 * Reads string data from the stream into a until the specified [pattern] | |
| 62 * occurs. When the pattern occours the specified [callback] is called with | |
| 63 * the string data including the pattern. If the pattern is not found before | |
| 64 * [maxLength] characters have been received the error handler will be | |
| 65 * called. | |
| 66 */ | |
| 67 void readUntil(String pattern, | |
| 68 void callback(String data), | |
| 69 [int maxLength = -1]); | |
| 70 | |
| 71 /** | |
| 72 * Reads as many characters as is available from the stream. If no data is | |
| 73 * available null will be returned and the specified callback will | |
| 74 * be called when data becomes available. | |
| 75 */ | |
| 76 String read(void callback()); | |
|
dcarlson
2011/10/17 21:05:20
optional param -- see above.
Søren Gjesse
2011/10/18 15:23:20
Removed the callback instead.
| |
| 77 | |
| 78 /** | |
| 79 * Sets the encoding to be used when reading string data to the | |
| 80 * stream. The default encoding is UTF-8. | |
| 81 */ | |
| 82 void set encoding(String encoding); | |
|
dcarlson
2011/10/17 21:05:20
getter?
Søren Gjesse
2011/10/18 15:23:20
Only getter now - removed setter.
| |
| 83 } | |
| OLD | NEW |