mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 00:20:38 +01:00
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>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 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');
|
|
|
|
module.exports = LazyTransform;
|
|
|
|
function LazyTransform(options) {
|
|
this._options = options;
|
|
this.writable = true;
|
|
this.readable = true;
|
|
}
|
|
util.inherits(LazyTransform, stream.Transform);
|
|
|
|
[
|
|
'_readableState',
|
|
'_writableState',
|
|
'_transformState'
|
|
].forEach(function(prop, i, props) {
|
|
Object.defineProperty(LazyTransform.prototype, prop, {
|
|
get: function() {
|
|
stream.Transform.call(this, this._options);
|
|
this._writableState.decodeStrings = false;
|
|
this._writableState.defaultEncoding = 'latin1';
|
|
return this[prop];
|
|
},
|
|
set: function(val) {
|
|
Object.defineProperty(this, prop, {
|
|
value: val,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true
|
|
});
|
|
},
|
|
configurable: true,
|
|
enumerable: true
|
|
});
|
|
});
|