Path: blob/trunk/third_party/closure/goog/net/streams/nodereadablestream.js
1865 views
// Copyright 2015 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview the API spec for the closure polyfill of Node stream.Readable.16*17* Node streams API is specified at https://nodejs.org/api/stream.html18*19* Only a subset of Node streams API (under the object mode) will be supported.20*21* It's our belief that Node and whatwg streams will eventually22* converge. As it happens, we will add a whatwg streams polyfill too.23* (https://github.com/whatwg/streams)24*25* This API requires no special server-side support other than the standard26* HTTP semantics. Message framing only relies on MIME types such as JSON27* to support atomic message delivery (e.g. elements of a JSON array).28* Other streaming-related features such as cancellation and keep-alive are29* exposed/constrained by the Node streams API semantics.30*31* Flow-control support is limited due to the underlying use of XHR. That is,32* this version will assume the "flowing mode", and the read method is not33* provided.34*35*/3637goog.provide('goog.net.streams.NodeReadableStream');38394041/**42* This interface represents a readable stream.43*44* @interface45*/46goog.net.streams.NodeReadableStream = function() {};474849/**50* Read events for the stream.51* @enum {string}52*/53goog.net.streams.NodeReadableStream.EventType = {54READABLE: 'readable',55DATA: 'data',56END: 'end',57CLOSE: 'close',58ERROR: 'error'59};606162/**63* Register a callback to handle I/O events.64*65* See https://iojs.org/api/events.html66*67* Note that under the object mode, an event of DATA will deliver a message68* of 1) JSON compliant JS object, including arrays; or 2) an ArrayBuffer.69*70* Ordering: messages will be delivered to callbacks in their registration71* order. There is no ordering between on() and once() callbacks.72*73* Exceptions from callbacks will be caught and ignored.74*75* @param {string} eventType The event type76* @param {function(!Object=)} callback The call back to handle the event with77* an optional input object78* @return {goog.net.streams.NodeReadableStream} this object79*/80goog.net.streams.NodeReadableStream.prototype.on = goog.abstractMethod;818283/**84* Register a callback to handle I/O events. This is an alias to on().85*86* @param {string} eventType The event type87* @param {function(!Object=)} callback The call back to handle the event with88* an optional input object89* @return {goog.net.streams.NodeReadableStream} this object90*/91goog.net.streams.NodeReadableStream.prototype.addListener = goog.abstractMethod;929394/**95* Unregister an existing callback, including one-time callbacks.96*97* @param {string} eventType The event type98* @param {function(!Object=)} callback The call back to unregister99* @return {goog.net.streams.NodeReadableStream} this object100*/101goog.net.streams.NodeReadableStream.prototype.removeListener =102goog.abstractMethod;103104105/**106* Register a one-time callback to handle I/O events.107*108* @param {string} eventType The event type109* @param {function(!Object=)} callback The call back to handle the event with110* an optional input object111* @return {goog.net.streams.NodeReadableStream} this object112*/113goog.net.streams.NodeReadableStream.prototype.once = goog.abstractMethod;114115116