mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
1ae172b272
Makes LazyTransform writable by Streams1 by assigning .writable = true before the actual classes are loaded. Fixes: https://github.com/nodejs/node/issues/12269 PR-URL: https://github.com/nodejs/node/pull/12380 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
63 lines
1.5 KiB
JavaScript
63 lines
1.5 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 stream = require('stream');
|
|
const util = require('util');
|
|
const crypto = require('crypto');
|
|
|
|
module.exports = LazyTransform;
|
|
|
|
function LazyTransform(options) {
|
|
this._options = options;
|
|
this.writable = true;
|
|
this.readable = true;
|
|
}
|
|
util.inherits(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 = crypto.DEFAULT_ENCODING;
|
|
}
|
|
|
|
return this[name];
|
|
};
|
|
}
|
|
|
|
function makeSetter(name) {
|
|
return function(val) {
|
|
Object.defineProperty(this, name, {
|
|
value: val,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true
|
|
});
|
|
};
|
|
}
|
|
|
|
Object.defineProperties(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
|
|
}
|
|
});
|