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 |
| 9 * on a given input. | 9 * on a given input. |
| 10 */ | 10 */ |
| 11 interface InputStream { | 11 interface InputStream { |
| 12 /** | 12 /** |
| 13 * Reads [len] bytes into [buffer] buffer starting at [offset] offset. | 13 * Reads as much data as is available from the stream. If no data is |
| 14 * [callback] callback is invoked on completion unless it is null. | 14 * available null will be returned. |
| 15 */ | 15 */ |
| 16 bool read(List<int> buffer, int offset, int len, void callback()); | 16 List<int> read(); |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Reads data from the stream into a buffer until a given [pattern] occurs and | 19 * The data handler gets called when data is available. |
| 20 * hands that buffer over as an input to the registered [callback]. | |
| 21 * The callback is not invoked if a read error occurs. | |
| 22 */ | 20 */ |
| 23 void readUntil(List<int> pattern, void callback(List<int> buffer)); | 21 void set dataHandler(void callback()); |
|
sra1
2011/10/18 23:45:51
There is a subtle relationship between the number
Søren Gjesse
2011/10/19 14:45:41
That should hopefully be the case - unless the OS
| |
| 22 | |
| 23 /** | |
| 24 * The close handler gets called when the underlying communication | |
| 25 * channel is closed and no more data will become available. Not all | |
| 26 * types of communication channels will emit close events. | |
| 27 */ | |
| 28 void set closeHandler(void callback()); | |
| 29 | |
| 30 /** | |
| 31 * The error handler gets called when the underlying communication | |
| 32 * channel gets into some kind of error situation. | |
| 33 */ | |
| 34 void set errorHandler(void callback(StreamError error)); | |
| 24 } | 35 } |
| 36 | |
| 37 | |
| 38 interface StringInputStream factory _StringInputStream { | |
|
dcarlson
2011/10/18 17:26:19
I'm surprised that it does not generate close/erro
Søren Gjesse
2011/10/19 14:45:41
No, it should also generate the close and error ev
| |
| 39 /** | |
| 40 * Decodes a binary input stream into characters using the specified | |
| 41 * encoding. | |
| 42 */ | |
| 43 StringInputStream(InputStream input, [String encoding = "UTF-8"]); | |
|
dcarlson
2011/10/18 17:26:19
Could we add a dataHandler as an optional param?
Søren Gjesse
2011/10/19 14:45:41
Maybe, but then we should also do that for the Inp
| |
| 44 | |
| 45 /** | |
| 46 * Reads as many characters as is available from the stream. If no data is | |
| 47 * available null will be returned. | |
| 48 */ | |
| 49 String read(); | |
| 50 | |
| 51 /** | |
| 52 * Returns the encoding used to decode the binary data into characters. | |
| 53 */ | |
| 54 String get encoding(); | |
|
dcarlson
2011/10/18 17:26:19
Can the encoding be changed mid-stream?
Søren Gjesse
2011/10/19 14:45:41
No.
| |
| 55 | |
| 56 /** | |
| 57 * The data handler gets called when data is available. | |
| 58 */ | |
| 59 void set dataHandler(void callback()); | |
| 60 } | |
| 61 | |
| 62 | |
| 63 interface ProcessingInputStream factory _ProcessingInputStream { | |
| 64 ProcessingInputStream(InputStream input); | |
| 65 | |
| 66 /** | |
| 67 * Reads [len] bytes from the stream. When the bytes have been read the | |
| 68 * specified [callback] is called with the data. | |
| 69 */ | |
| 70 void readFully(int len, void callback(List<int> buffer)); | |
| 71 | |
| 72 /** | |
| 73 * Reads data from the stream into a buffer until the specified [pattern] | |
| 74 * occurs. When the pattern occours the specified [callback] is called with | |
| 75 * the data including the pattern. If the pattern is not found before | |
| 76 * [maxLength] bytes have been received the error handler will be called. | |
| 77 */ | |
| 78 void readUntil(List<int> pattern, | |
| 79 void callback(List<int> buffer), | |
| 80 [int maxLength = -1]); | |
| 81 | |
| 82 /** | |
| 83 * Reads as much data as is available from the stream. The supplied | |
| 84 * callback is called with the data. | |
| 85 */ | |
| 86 void read(void callback(List<int> data)); | |
| 87 | |
| 88 /** | |
| 89 * The close handler gets called when the underlying communication | |
| 90 * channel gets closed. Not all types of communication channels will | |
| 91 * emit close events. | |
| 92 */ | |
| 93 void set closeHandler(void callback()); | |
|
sra1
2011/10/18 23:45:51
This implies that the underlying's closeHander set
Søren Gjesse
2011/10/19 14:45:41
My take on this is that if you wrap an InputStream
| |
| 94 | |
| 95 /** | |
| 96 * The error handler gets called when the underlying communication | |
| 97 * channel gets into some kind of error situation. | |
| 98 */ | |
| 99 void set errorHandler(void callback(StreamError error)); | |
| 100 } | |
| OLD | NEW |