mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 13:09:42 +00:00

Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
// LazyTransform is a special type of Transform stream that is lazily loaded.
|
|
// This is used for performance with bi-API-ship: when two APIs are available
|
|
// for the stream, one conventional and one non-conventional.
|
|
'use strict';
|
|
|
|
const {
|
|
ObjectDefineProperties,
|
|
ObjectDefineProperty,
|
|
ObjectSetPrototypeOf,
|
|
} = primordials;
|
|
|
|
const stream = require('stream');
|
|
|
|
const {
|
|
getDefaultEncoding
|
|
} = require('internal/crypto/util');
|
|
|
|
module.exports = LazyTransform;
|
|
|
|
function LazyTransform(options) {
|
|
this._options = options;
|
|
this.writable = true;
|
|
this.readable = true;
|
|
}
|
|
ObjectSetPrototypeOf(LazyTransform.prototype, stream.Transform.prototype);
|
|
ObjectSetPrototypeOf(LazyTransform, stream.Transform);
|
|
|
|
function makeGetter(name) {
|
|
return function() {
|
|
stream.Transform.call(this, this._options);
|
|
this._writableState.decodeStrings = false;
|
|
|
|
if (!this._options || !this._options.defaultEncoding) {
|
|
this._writableState.defaultEncoding = getDefaultEncoding();
|
|
}
|
|
|
|
return this[name];
|
|
};
|
|
}
|
|
|
|
function makeSetter(name) {
|
|
return function(val) {
|
|
ObjectDefineProperty(this, name, {
|
|
value: val,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true
|
|
});
|
|
};
|
|
}
|
|
|
|
ObjectDefineProperties(LazyTransform.prototype, {
|
|
_readableState: {
|
|
get: makeGetter('_readableState'),
|
|
set: makeSetter('_readableState'),
|
|
configurable: true,
|
|
enumerable: true
|
|
},
|
|
_writableState: {
|
|
get: makeGetter('_writableState'),
|
|
set: makeSetter('_writableState'),
|
|
configurable: true,
|
|
enumerable: true
|
|
},
|
|
_transformState: {
|
|
get: makeGetter('_transformState'),
|
|
set: makeSetter('_transformState'),
|
|
configurable: true,
|
|
enumerable: true
|
|
}
|
|
});
|