mirror of https://github.com/lukechilds/node.git
Browse Source
This commit refactors LazyTransform from the crypto implementation (lib/crypto.js) into an internal module (not publicy accessible) in internal/streams/lazy_transform.js. This promotes a more modular core design and removes code bloat in crypto, as LazyTransform didn't specifically have anything to do with cryptography, but rather a fast way to support two APIs on a stream. PR-URL: https://github.com/nodejs/node/pull/2566 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>v4.x
Brendan Ashworth
9 years ago
committed by
Jeremiah Senkpiel
3 changed files with 41 additions and 31 deletions
@ -0,0 +1,39 @@ |
|||
// 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; |
|||
} |
|||
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 = 'binary'; |
|||
return this[prop]; |
|||
}, |
|||
set: function(val) { |
|||
Object.defineProperty(this, prop, { |
|||
value: val, |
|||
enumerable: true, |
|||
configurable: true, |
|||
writable: true |
|||
}); |
|||
}, |
|||
configurable: true, |
|||
enumerable: true |
|||
}); |
|||
}); |
Loading…
Reference in new issue