MCPcopy Index your code
hub / github.com/nodejs/node / Transform

Function Transform

lib/internal/streams/transform.js:82–124  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

80const kCallback = Symbol('kCallback');
81
82function Transform(options) {
83 if (!(this instanceof Transform))
84 return new Transform(options);
85
86 // TODO (ronag): This should preferably always be
87 // applied but would be semver-major. Or even better;
88 // make Transform a Readable with the Writable interface.
89 const readableHighWaterMark = options ? getHighWaterMark(this, options, 'readableHighWaterMark', true) : null;
90 if (readableHighWaterMark === 0) {
91 // A Duplex will buffer both on the writable and readable side while
92 // a Transform just wants to buffer hwm number of elements. To avoid
93 // buffering twice we disable buffering on the writable side.
94 options = {
95 ...options,
96 highWaterMark: null,
97 readableHighWaterMark,
98 writableHighWaterMark: options.writableHighWaterMark || 0,
99 };
100 }
101
102 Duplex.call(this, options);
103
104 // We have implemented the _read method, and done the other things
105 // that Readable wants before the first _read call, so unset the
106 // sync guard flag.
107 this._readableState.sync = false;
108
109 this[kCallback] = null;
110
111 if (options) {
112 if (typeof options.transform === 'function')
113 this._transform = options.transform;
114
115 if (typeof options.flush === 'function')
116 this._flush = options.flush;
117 }
118
119 // When the writable side finishes, then flush out anything remaining.
120 // Backwards compat. Some Transform streams incorrectly implement _final
121 // instead of or in addition to _flush. By using 'prefinish' instead of
122 // implementing _final we continue supporting this unfortunate use case.
123 this.on('prefinish', prefinish);
124}
125
126function final(cb) {
127 if (typeof this._flush === 'function' && !this.destroyed) {

Callers

nothing calls this directly

Calls 3

getHighWaterMarkFunction · 0.85
callMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…