| 1 |
// Copyright 2015 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview the API spec for the closure polyfill of Node stream.Readable. |
| 17 |
* |
| 18 |
* Node streams API is specified at https://nodejs.org/api/stream.html |
| 19 |
* |
| 20 |
* Only a subset of Node streams API (under the object mode) will be supported. |
| 21 |
* |
| 22 |
* It's our belief that Node and whatwg streams will eventually |
| 23 |
* converge. As it happens, we will add a whatwg streams polyfill too. |
| 24 |
* (https://github.com/whatwg/streams) |
| 25 |
* |
| 26 |
* This API requires no special server-side support other than the standard |
| 27 |
* HTTP semantics. Message framing only relies on MIME types such as JSON |
| 28 |
* to support atomic message delivery (e.g. elements of a JSON array). |
| 29 |
* Other streaming-related features such as cancellation and keep-alive are |
| 30 |
* exposed/constrained by the Node streams API semantics. |
| 31 |
* |
| 32 |
* Flow-control support is limited due to the underlying use of XHR. That is, |
| 33 |
* this version will assume the "flowing mode", and the read method is not |
| 34 |
* provided. |
| 35 |
* |
| 36 |
*/ |
| 37 |
|
| 38 |
goog.provide('goog.net.streams.NodeReadableStream'); |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
/** |
| 43 |
* This interface represents a readable stream. |
| 44 |
* |
| 45 |
* @interface |
| 46 |
*/ |
| 47 |
goog.net.streams.NodeReadableStream = function() {}; |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Read events for the stream. |
| 52 |
* @enum {string} |
| 53 |
*/ |
| 54 |
goog.net.streams.NodeReadableStream.EventType = { |
| 55 |
READABLE: 'readable', |
| 56 |
DATA: 'data', |
| 57 |
END: 'end', |
| 58 |
CLOSE: 'close', |
| 59 |
ERROR: 'error' |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* Register a callback to handle I/O events. |
| 65 |
* |
| 66 |
* See https://iojs.org/api/events.html |
| 67 |
* |
| 68 |
* Note that under the object mode, an event of DATA will deliver a message |
| 69 |
* of 1) JSON compliant JS object, including arrays; or 2) an ArrayBuffer. |
| 70 |
* |
| 71 |
* Ordering: messages will be delivered to callbacks in their registration |
| 72 |
* order. There is no ordering between on() and once() callbacks. |
| 73 |
* |
| 74 |
* Exceptions from callbacks will be caught and ignored. |
| 75 |
* |
| 76 |
* @param {string} eventType The event type |
| 77 |
* @param {function(!Object=)} callback The call back to handle the event with |
| 78 |
* an optional input object |
| 79 |
* @return {goog.net.streams.NodeReadableStream} this object |
| 80 |
*/ |
| 81 |
goog.net.streams.NodeReadableStream.prototype.on = goog.abstractMethod; |
| 82 |
|
| 83 |
|
| 84 |
/** |
| 85 |
* Register a callback to handle I/O events. This is an alias to on(). |
| 86 |
* |
| 87 |
* @param {string} eventType The event type |
| 88 |
* @param {function(!Object=)} callback The call back to handle the event with |
| 89 |
* an optional input object |
| 90 |
* @return {goog.net.streams.NodeReadableStream} this object |
| 91 |
*/ |
| 92 |
goog.net.streams.NodeReadableStream.prototype.addListener = goog.abstractMethod; |
| 93 |
|
| 94 |
|
| 95 |
/** |
| 96 |
* Unregister an existing callback, including one-time callbacks. |
| 97 |
* |
| 98 |
* @param {string} eventType The event type |
| 99 |
* @param {function(!Object=)} callback The call back to unregister |
| 100 |
* @return {goog.net.streams.NodeReadableStream} this object |
| 101 |
*/ |
| 102 |
goog.net.streams.NodeReadableStream.prototype.removeListener = |
| 103 |
goog.abstractMethod; |
| 104 |
|
| 105 |
|
| 106 |
/** |
| 107 |
* Register a one-time callback to handle I/O events. |
| 108 |
* |
| 109 |
* @param {string} eventType The event type |
| 110 |
* @param {function(!Object=)} callback The call back to handle the event with |
| 111 |
* an optional input object |
| 112 |
* @return {goog.net.streams.NodeReadableStream} this object |
| 113 |
*/ |
| 114 |
goog.net.streams.NodeReadableStream.prototype.once = goog.abstractMethod; |