2017-01-03 21:16:48 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-11-22 15:59:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-06-28 08:29:01 +00:00
|
|
|
const {
|
|
|
|
ObjectDefineProperty,
|
2021-11-15 13:39:05 +00:00
|
|
|
ObjectKeys,
|
|
|
|
ReflectApply,
|
2020-06-28 08:29:01 +00:00
|
|
|
} = primordials;
|
|
|
|
|
|
|
|
const {
|
|
|
|
promisify: { custom: customPromisify },
|
|
|
|
} = require('internal/util');
|
|
|
|
|
2022-01-08 10:46:07 +00:00
|
|
|
const {
|
|
|
|
streamReturningOperators,
|
|
|
|
promiseReturningOperators,
|
|
|
|
} = require('internal/streams/operators');
|
2022-02-05 16:47:46 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
codes: {
|
|
|
|
ERR_ILLEGAL_CONSTRUCTOR,
|
|
|
|
},
|
|
|
|
} = require('internal/errors');
|
2021-07-19 06:19:03 +00:00
|
|
|
const compose = require('internal/streams/compose');
|
2023-03-29 18:02:10 +00:00
|
|
|
const { setDefaultHighWaterMark, getDefaultHighWaterMark } = require('internal/streams/state');
|
2021-06-17 20:25:34 +00:00
|
|
|
const { pipeline } = require('internal/streams/pipeline');
|
2021-05-02 16:17:18 +00:00
|
|
|
const { destroyer } = require('internal/streams/destroy');
|
2018-04-04 14:52:19 +00:00
|
|
|
const eos = require('internal/streams/end-of-stream');
|
2019-10-20 11:36:49 +00:00
|
|
|
const internalBuffer = require('internal/buffer');
|
2017-01-09 18:05:06 +00:00
|
|
|
|
2021-05-19 18:32:18 +00:00
|
|
|
const promises = require('stream/promises');
|
2021-12-09 08:15:12 +00:00
|
|
|
const utils = require('internal/streams/utils');
|
2024-03-20 17:27:29 +00:00
|
|
|
const { isArrayBufferView, isUint8Array } = require('internal/util/types');
|
2020-06-28 08:29:01 +00:00
|
|
|
|
2020-09-18 13:38:57 +00:00
|
|
|
const Stream = module.exports = require('internal/streams/legacy').Stream;
|
2023-03-24 07:20:18 +00:00
|
|
|
|
|
|
|
Stream.isDestroyed = utils.isDestroyed;
|
2021-12-09 08:15:12 +00:00
|
|
|
Stream.isDisturbed = utils.isDisturbed;
|
|
|
|
Stream.isErrored = utils.isErrored;
|
2021-12-16 13:32:02 +00:00
|
|
|
Stream.isReadable = utils.isReadable;
|
2023-03-24 07:20:18 +00:00
|
|
|
Stream.isWritable = utils.isWritable;
|
|
|
|
|
2020-09-16 17:05:06 +00:00
|
|
|
Stream.Readable = require('internal/streams/readable');
|
2024-08-23 07:31:55 +00:00
|
|
|
const streamKeys = ObjectKeys(streamReturningOperators);
|
|
|
|
for (let i = 0; i < streamKeys.length; i++) {
|
|
|
|
const key = streamKeys[i];
|
2022-01-08 10:46:07 +00:00
|
|
|
const op = streamReturningOperators[key];
|
2022-02-05 16:47:46 +00:00
|
|
|
function fn(...args) {
|
|
|
|
if (new.target) {
|
2023-09-28 09:57:38 +00:00
|
|
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
2022-02-05 16:47:46 +00:00
|
|
|
}
|
2021-11-15 13:39:05 +00:00
|
|
|
return Stream.Readable.from(ReflectApply(op, this, args));
|
2022-02-05 16:47:46 +00:00
|
|
|
}
|
2022-06-03 08:23:58 +00:00
|
|
|
ObjectDefineProperty(fn, 'name', { __proto__: null, value: op.name });
|
|
|
|
ObjectDefineProperty(fn, 'length', { __proto__: null, value: op.length });
|
2022-02-05 16:47:46 +00:00
|
|
|
ObjectDefineProperty(Stream.Readable.prototype, key, {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2022-02-05 16:47:46 +00:00
|
|
|
value: fn,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
2022-02-23 21:06:00 +00:00
|
|
|
writable: true,
|
2022-02-05 16:47:46 +00:00
|
|
|
});
|
2021-11-15 13:39:05 +00:00
|
|
|
}
|
2024-08-23 07:31:55 +00:00
|
|
|
const promiseKeys = ObjectKeys(promiseReturningOperators);
|
|
|
|
for (let i = 0; i < promiseKeys.length; i++) {
|
|
|
|
const key = promiseKeys[i];
|
2022-01-08 10:46:07 +00:00
|
|
|
const op = promiseReturningOperators[key];
|
2022-02-05 16:47:46 +00:00
|
|
|
function fn(...args) {
|
2022-02-23 21:06:00 +00:00
|
|
|
if (new.target) {
|
2023-09-28 09:57:38 +00:00
|
|
|
throw new ERR_ILLEGAL_CONSTRUCTOR();
|
2022-02-23 21:06:00 +00:00
|
|
|
}
|
2022-01-08 10:46:07 +00:00
|
|
|
return ReflectApply(op, this, args);
|
2022-02-05 16:47:46 +00:00
|
|
|
}
|
2022-06-03 08:23:58 +00:00
|
|
|
ObjectDefineProperty(fn, 'name', { __proto__: null, value: op.name });
|
|
|
|
ObjectDefineProperty(fn, 'length', { __proto__: null, value: op.length });
|
2022-02-05 16:47:46 +00:00
|
|
|
ObjectDefineProperty(Stream.Readable.prototype, key, {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2022-02-05 16:47:46 +00:00
|
|
|
value: fn,
|
|
|
|
enumerable: false,
|
|
|
|
configurable: true,
|
2022-02-23 21:06:00 +00:00
|
|
|
writable: true,
|
2022-02-05 16:47:46 +00:00
|
|
|
});
|
2022-01-08 10:46:07 +00:00
|
|
|
}
|
2020-09-16 17:05:06 +00:00
|
|
|
Stream.Writable = require('internal/streams/writable');
|
|
|
|
Stream.Duplex = require('internal/streams/duplex');
|
|
|
|
Stream.Transform = require('internal/streams/transform');
|
|
|
|
Stream.PassThrough = require('internal/streams/passthrough');
|
2024-07-26 08:09:23 +00:00
|
|
|
Stream.duplexPair = require('internal/streams/duplexpair');
|
2018-04-04 14:52:19 +00:00
|
|
|
Stream.pipeline = pipeline;
|
2020-12-07 16:42:46 +00:00
|
|
|
const { addAbortSignal } = require('internal/streams/add-abort-signal');
|
|
|
|
Stream.addAbortSignal = addAbortSignal;
|
2018-04-04 14:52:19 +00:00
|
|
|
Stream.finished = eos;
|
2021-05-02 16:17:18 +00:00
|
|
|
Stream.destroy = destroyer;
|
2021-07-19 06:19:03 +00:00
|
|
|
Stream.compose = compose;
|
2023-03-29 18:02:10 +00:00
|
|
|
Stream.setDefaultHighWaterMark = setDefaultHighWaterMark;
|
|
|
|
Stream.getDefaultHighWaterMark = getDefaultHighWaterMark;
|
2021-06-18 06:08:50 +00:00
|
|
|
|
2020-06-28 08:29:01 +00:00
|
|
|
ObjectDefineProperty(Stream, 'promises', {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2020-06-28 08:29:01 +00:00
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
2021-05-19 18:32:18 +00:00
|
|
|
return promises;
|
2023-02-12 18:26:21 +00:00
|
|
|
},
|
2020-06-28 08:29:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ObjectDefineProperty(pipeline, customPromisify, {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2020-06-28 08:29:01 +00:00
|
|
|
enumerable: true,
|
|
|
|
get() {
|
2021-05-19 18:32:18 +00:00
|
|
|
return promises.pipeline;
|
2023-02-12 18:26:21 +00:00
|
|
|
},
|
2020-06-28 08:29:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ObjectDefineProperty(eos, customPromisify, {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2020-06-28 08:29:01 +00:00
|
|
|
enumerable: true,
|
|
|
|
get() {
|
2021-05-19 18:32:18 +00:00
|
|
|
return promises.finished;
|
2023-02-12 18:26:21 +00:00
|
|
|
},
|
2020-06-28 08:29:01 +00:00
|
|
|
});
|
|
|
|
|
2011-10-24 21:52:10 +00:00
|
|
|
// Backwards-compat with node 0.4.x
|
|
|
|
Stream.Stream = Stream;
|
2017-01-09 18:05:06 +00:00
|
|
|
|
2024-03-20 17:27:29 +00:00
|
|
|
Stream._isArrayBufferView = isArrayBufferView;
|
|
|
|
Stream._isUint8Array = isUint8Array;
|
2019-10-20 11:36:49 +00:00
|
|
|
Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) {
|
|
|
|
return new internalBuffer.FastBuffer(chunk.buffer,
|
|
|
|
chunk.byteOffset,
|
|
|
|
chunk.byteLength);
|
|
|
|
};
|