Skip to content

Commit db2d1ca

Browse files
ronagcodebytere
authored andcommitted
stream: runtime deprecate Transform._transformState
Transform._transformState is removed in future version as part of a refactoring. Refs: #32763 Refs: #33105 (comment) Backport-PR-URL: #33126 PR-URL: #32763
1 parent 2c568c8 commit db2d1ca

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

doc/api/deprecations.md

+12
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,18 @@ The `repl` module exports a `_builtinLibs` property that contains an array with
26952695
native modules. It was incomplete so far and instead it's better to rely upon
26962696
`require('module').builtinModules`.
26972697

2698+
<a id="DEP0143"></a>
2699+
### DEP0143: `Transform._transformState`
2700+
<!-- YAML
2701+
changes:
2702+
- version: REPLACEME
2703+
pr-url: https://github.com/nodejs/node/pull/33126
2704+
description: Runtime deprecation.
2705+
-->
2706+
Type: Runtime
2707+
`Transform._transformState` will be removed in future versions where it is
2708+
no longer required due to simplification of the implementation.
2709+
26982710
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
26992711
[`--throw-deprecation`]: cli.html#cli_throw_deprecation
27002712
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size

lib/_stream_transform.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
'use strict';
6565

6666
const {
67+
ObjectDefineProperty,
6768
ObjectSetPrototypeOf,
69+
Symbol
6870
} = primordials;
6971

7072
module.exports = Transform;
@@ -75,12 +77,15 @@ const {
7577
ERR_TRANSFORM_WITH_LENGTH_0
7678
} = require('internal/errors').codes;
7779
const Duplex = require('_stream_duplex');
80+
const internalUtil = require('internal/util');
81+
7882
ObjectSetPrototypeOf(Transform.prototype, Duplex.prototype);
7983
ObjectSetPrototypeOf(Transform, Duplex);
8084

85+
const kTransformState = Symbol('kTransformState');
8186

8287
function afterTransform(er, data) {
83-
const ts = this._transformState;
88+
const ts = this[kTransformState];
8489
ts.transforming = false;
8590

8691
const cb = ts.writecb;
@@ -111,7 +116,7 @@ function Transform(options) {
111116

112117
Duplex.call(this, options);
113118

114-
this._transformState = {
119+
this[kTransformState] = {
115120
afterTransform: afterTransform.bind(this),
116121
needTransform: false,
117122
transforming: false,
@@ -147,8 +152,17 @@ function prefinish() {
147152
}
148153
}
149154

155+
ObjectDefineProperty(Transform.prototype, '_transformState', {
156+
get: internalUtil.deprecate(function() {
157+
return this[kTransformState];
158+
}, 'Transform.prototype._transformState is deprecated', 'DEP0143'),
159+
set: internalUtil.deprecate(function(val) {
160+
this[kTransformState] = val;
161+
}, 'Transform.prototype._transformState is deprecated', 'DEP0143')
162+
});
163+
150164
Transform.prototype.push = function(chunk, encoding) {
151-
this._transformState.needTransform = false;
165+
this[kTransformState].needTransform = false;
152166
return Duplex.prototype.push.call(this, chunk, encoding);
153167
};
154168

@@ -167,7 +181,7 @@ Transform.prototype._transform = function(chunk, encoding, cb) {
167181
};
168182

169183
Transform.prototype._write = function(chunk, encoding, cb) {
170-
const ts = this._transformState;
184+
const ts = this[kTransformState];
171185
ts.writecb = cb;
172186
ts.writechunk = chunk;
173187
ts.writeencoding = encoding;
@@ -184,7 +198,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
184198
// _transform does all the work.
185199
// That we got here means that the readable side wants more data.
186200
Transform.prototype._read = function(n) {
187-
const ts = this._transformState;
201+
const ts = this[kTransformState];
188202

189203
if (ts.writechunk !== null && !ts.transforming) {
190204
ts.transforming = true;
@@ -215,7 +229,7 @@ function done(stream, er, data) {
215229
if (stream._writableState.length)
216230
throw new ERR_TRANSFORM_WITH_LENGTH_0();
217231

218-
if (stream._transformState.transforming)
232+
if (stream[kTransformState].transforming)
219233
throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
220234
return stream.push(null);
221235
}

0 commit comments

Comments
 (0)