UNPKG

nstdlib-nightly

Version:

Node.js standard library converted to runtime-agnostic ES modules.

152 lines (140 loc) 5.65 kB
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/stream.js import * as __hoisted_internal_streams_readable__ from "nstdlib/lib/internal/streams/readable"; import * as __hoisted_internal_streams_writable__ from "nstdlib/lib/internal/streams/writable"; import * as __hoisted_internal_streams_duplex__ from "nstdlib/lib/internal/streams/duplex"; import * as __hoisted_internal_streams_transform__ from "nstdlib/lib/internal/streams/transform"; import * as __hoisted_internal_streams_passthrough__ from "nstdlib/lib/internal/streams/passthrough"; import * as __hoisted_internal_streams_duplexpair__ from "nstdlib/lib/internal/streams/duplexpair"; import { promisify as __promisify__ } from "nstdlib/lib/internal/util"; import { streamReturningOperators, promiseReturningOperators, } from "nstdlib/lib/internal/streams/operators"; import { codes as __codes__ } from "nstdlib/lib/internal/errors"; import * as compose from "nstdlib/lib/internal/streams/compose"; import { setDefaultHighWaterMark, getDefaultHighWaterMark, } from "nstdlib/lib/internal/streams/state"; import { pipeline } from "nstdlib/lib/internal/streams/pipeline"; import { destroyer } from "nstdlib/lib/internal/streams/destroy"; import * as eos from "nstdlib/lib/internal/streams/end-of-stream"; import * as internalBuffer from "nstdlib/lib/internal/buffer"; import * as promises from "nstdlib/lib/stream/promises"; import * as utils from "nstdlib/lib/internal/streams/utils"; import { isArrayBufferView, isUint8Array, } from "nstdlib/lib/internal/util/types"; import { addAbortSignal } from "nstdlib/lib/internal/streams/add-abort-signal"; // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to permit // persons to whom the Software is furnished to do so, subject to the // following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. const { custom: customPromisify } = __promisify__; const { ERR_ILLEGAL_CONSTRUCTOR } = __codes__; const Stream = require("internal/streams/legacy").Stream; export { Stream as default }; Stream.isDestroyed = utils.isDestroyed; Stream.isDisturbed = utils.isDisturbed; Stream.isErrored = utils.isErrored; Stream.isReadable = utils.isReadable; Stream.isWritable = utils.isWritable; Stream.Readable = __hoisted_internal_streams_readable__; for (const key of Object.keys(streamReturningOperators)) { const op = streamReturningOperators[key]; function fn(...args) { if (new.target) { throw new ERR_ILLEGAL_CONSTRUCTOR(); } return Stream.Readable.from(ReflectApply(op, this, args)); } Object.defineProperty(fn, "name", { __proto__: null, value: op.name }); Object.defineProperty(fn, "length", { __proto__: null, value: op.length }); Object.defineProperty(Stream.Readable.prototype, key, { __proto__: null, value: fn, enumerable: false, configurable: true, writable: true, }); } for (const key of Object.keys(promiseReturningOperators)) { const op = promiseReturningOperators[key]; function fn(...args) { if (new.target) { throw new ERR_ILLEGAL_CONSTRUCTOR(); } return ReflectApply(op, this, args); } Object.defineProperty(fn, "name", { __proto__: null, value: op.name }); Object.defineProperty(fn, "length", { __proto__: null, value: op.length }); Object.defineProperty(Stream.Readable.prototype, key, { __proto__: null, value: fn, enumerable: false, configurable: true, writable: true, }); } Stream.Writable = __hoisted_internal_streams_writable__; Stream.Duplex = __hoisted_internal_streams_duplex__; Stream.Transform = __hoisted_internal_streams_transform__; Stream.PassThrough = __hoisted_internal_streams_passthrough__; Stream.duplexPair = __hoisted_internal_streams_duplexpair__; Stream.pipeline = pipeline; Stream.addAbortSignal = addAbortSignal; Stream.finished = eos; Stream.destroy = destroyer; Stream.compose = compose; Stream.setDefaultHighWaterMark = setDefaultHighWaterMark; Stream.getDefaultHighWaterMark = getDefaultHighWaterMark; Object.defineProperty(Stream, "promises", { __proto__: null, configurable: true, enumerable: true, get() { return promises; }, }); Object.defineProperty(pipeline, customPromisify, { __proto__: null, enumerable: true, get() { return promises.pipeline; }, }); Object.defineProperty(eos, customPromisify, { __proto__: null, enumerable: true, get() { return promises.finished; }, }); // Backwards-compat with node 0.4.x Stream.Stream = Stream; Stream._isArrayBufferView = isArrayBufferView; Stream._isUint8Array = isUint8Array; Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) { return new internalBuffer.FastBuffer( chunk.buffer, chunk.byteOffset, chunk.byteLength, ); };