2015-08-26 14:41:28 -07:00
|
|
|
// 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';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
|
|
|
ObjectDefineProperties,
|
|
|
|
ObjectDefineProperty,
|
|
|
|
ObjectSetPrototypeOf,
|
|
|
|
} = primordials;
|
2019-04-09 09:55:53 +02:00
|
|
|
|
2015-08-26 14:41:28 -07:00
|
|
|
const stream = require('stream');
|
2018-11-17 00:18:55 +08:00
|
|
|
|
2015-08-26 14:41:28 -07:00
|
|
|
module.exports = LazyTransform;
|
|
|
|
|
|
|
|
function LazyTransform(options) {
|
|
|
|
this._options = options;
|
|
|
|
}
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectSetPrototypeOf(LazyTransform.prototype, stream.Transform.prototype);
|
|
|
|
ObjectSetPrototypeOf(LazyTransform, stream.Transform);
|
2015-08-26 14:41:28 -07:00
|
|
|
|
2017-02-26 17:54:40 -08:00
|
|
|
function makeGetter(name) {
|
|
|
|
return function() {
|
2021-04-15 15:05:42 +02:00
|
|
|
stream.Transform.call(this, this._options);
|
2017-02-26 17:54:40 -08:00
|
|
|
this._writableState.decodeStrings = false;
|
|
|
|
return this[name];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeSetter(name) {
|
|
|
|
return function(val) {
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperty(this, name, {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2017-02-26 17:54:40 -08:00
|
|
|
value: val,
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true,
|
2023-02-18 18:53:57 +01:00
|
|
|
writable: true,
|
2017-02-26 17:54:40 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperties(LazyTransform.prototype, {
|
2017-02-26 17:54:40 -08:00
|
|
|
_readableState: {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2017-02-26 17:54:40 -08:00
|
|
|
get: makeGetter('_readableState'),
|
|
|
|
set: makeSetter('_readableState'),
|
|
|
|
configurable: true,
|
2023-02-18 18:53:57 +01:00
|
|
|
enumerable: true,
|
2017-02-26 17:54:40 -08:00
|
|
|
},
|
|
|
|
_writableState: {
|
2022-06-03 10:23:58 +02:00
|
|
|
__proto__: null,
|
2017-02-26 17:54:40 -08:00
|
|
|
get: makeGetter('_writableState'),
|
|
|
|
set: makeSetter('_writableState'),
|
|
|
|
configurable: true,
|
2023-02-18 18:53:57 +01:00
|
|
|
enumerable: true,
|
|
|
|
},
|
2015-08-26 14:41:28 -07:00
|
|
|
});
|