11cb0ef41Sopenharmony_ci// LazyTransform is a special type of Transform stream that is lazily loaded.
21cb0ef41Sopenharmony_ci// This is used for performance with bi-API-ship: when two APIs are available
31cb0ef41Sopenharmony_ci// for the stream, one conventional and one non-conventional.
41cb0ef41Sopenharmony_ci'use strict';
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst {
71cb0ef41Sopenharmony_ci  ObjectDefineProperties,
81cb0ef41Sopenharmony_ci  ObjectDefineProperty,
91cb0ef41Sopenharmony_ci  ObjectSetPrototypeOf,
101cb0ef41Sopenharmony_ci} = primordials;
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst stream = require('stream');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst {
151cb0ef41Sopenharmony_ci  getDefaultEncoding,
161cb0ef41Sopenharmony_ci} = require('internal/crypto/util');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cimodule.exports = LazyTransform;
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cifunction LazyTransform(options) {
211cb0ef41Sopenharmony_ci  this._options = options;
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ciObjectSetPrototypeOf(LazyTransform.prototype, stream.Transform.prototype);
241cb0ef41Sopenharmony_ciObjectSetPrototypeOf(LazyTransform, stream.Transform);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cifunction makeGetter(name) {
271cb0ef41Sopenharmony_ci  return function() {
281cb0ef41Sopenharmony_ci    stream.Transform.call(this, this._options);
291cb0ef41Sopenharmony_ci    this._writableState.decodeStrings = false;
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    if (!this._options || !this._options.defaultEncoding) {
321cb0ef41Sopenharmony_ci      this._writableState.defaultEncoding = getDefaultEncoding();
331cb0ef41Sopenharmony_ci    }
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci    return this[name];
361cb0ef41Sopenharmony_ci  };
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cifunction makeSetter(name) {
401cb0ef41Sopenharmony_ci  return function(val) {
411cb0ef41Sopenharmony_ci    ObjectDefineProperty(this, name, {
421cb0ef41Sopenharmony_ci      __proto__: null,
431cb0ef41Sopenharmony_ci      value: val,
441cb0ef41Sopenharmony_ci      enumerable: true,
451cb0ef41Sopenharmony_ci      configurable: true,
461cb0ef41Sopenharmony_ci      writable: true,
471cb0ef41Sopenharmony_ci    });
481cb0ef41Sopenharmony_ci  };
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ciObjectDefineProperties(LazyTransform.prototype, {
521cb0ef41Sopenharmony_ci  _readableState: {
531cb0ef41Sopenharmony_ci    __proto__: null,
541cb0ef41Sopenharmony_ci    get: makeGetter('_readableState'),
551cb0ef41Sopenharmony_ci    set: makeSetter('_readableState'),
561cb0ef41Sopenharmony_ci    configurable: true,
571cb0ef41Sopenharmony_ci    enumerable: true,
581cb0ef41Sopenharmony_ci  },
591cb0ef41Sopenharmony_ci  _writableState: {
601cb0ef41Sopenharmony_ci    __proto__: null,
611cb0ef41Sopenharmony_ci    get: makeGetter('_writableState'),
621cb0ef41Sopenharmony_ci    set: makeSetter('_writableState'),
631cb0ef41Sopenharmony_ci    configurable: true,
641cb0ef41Sopenharmony_ci    enumerable: true,
651cb0ef41Sopenharmony_ci  },
661cb0ef41Sopenharmony_ci});
67