64
64
'use strict' ;
65
65
66
66
const {
67
+ ObjectDefineProperty,
67
68
ObjectSetPrototypeOf,
69
+ Symbol
68
70
} = primordials ;
69
71
70
72
module . exports = Transform ;
@@ -75,12 +77,15 @@ const {
75
77
ERR_TRANSFORM_WITH_LENGTH_0
76
78
} = require ( 'internal/errors' ) . codes ;
77
79
const Duplex = require ( '_stream_duplex' ) ;
80
+ const internalUtil = require ( 'internal/util' ) ;
81
+
78
82
ObjectSetPrototypeOf ( Transform . prototype , Duplex . prototype ) ;
79
83
ObjectSetPrototypeOf ( Transform , Duplex ) ;
80
84
85
+ const kTransformState = Symbol ( 'kTransformState' ) ;
81
86
82
87
function afterTransform ( er , data ) {
83
- const ts = this . _transformState ;
88
+ const ts = this [ kTransformState ] ;
84
89
ts . transforming = false ;
85
90
86
91
const cb = ts . writecb ;
@@ -111,7 +116,7 @@ function Transform(options) {
111
116
112
117
Duplex . call ( this , options ) ;
113
118
114
- this . _transformState = {
119
+ this [ kTransformState ] = {
115
120
afterTransform : afterTransform . bind ( this ) ,
116
121
needTransform : false ,
117
122
transforming : false ,
@@ -147,8 +152,17 @@ function prefinish() {
147
152
}
148
153
}
149
154
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
+
150
164
Transform . prototype . push = function ( chunk , encoding ) {
151
- this . _transformState . needTransform = false ;
165
+ this [ kTransformState ] . needTransform = false ;
152
166
return Duplex . prototype . push . call ( this , chunk , encoding ) ;
153
167
} ;
154
168
@@ -167,7 +181,7 @@ Transform.prototype._transform = function(chunk, encoding, cb) {
167
181
} ;
168
182
169
183
Transform . prototype . _write = function ( chunk , encoding , cb ) {
170
- const ts = this . _transformState ;
184
+ const ts = this [ kTransformState ] ;
171
185
ts . writecb = cb ;
172
186
ts . writechunk = chunk ;
173
187
ts . writeencoding = encoding ;
@@ -184,7 +198,7 @@ Transform.prototype._write = function(chunk, encoding, cb) {
184
198
// _transform does all the work.
185
199
// That we got here means that the readable side wants more data.
186
200
Transform . prototype . _read = function ( n ) {
187
- const ts = this . _transformState ;
201
+ const ts = this [ kTransformState ] ;
188
202
189
203
if ( ts . writechunk !== null && ! ts . transforming ) {
190
204
ts . transforming = true ;
@@ -215,7 +229,7 @@ function done(stream, er, data) {
215
229
if ( stream . _writableState . length )
216
230
throw new ERR_TRANSFORM_WITH_LENGTH_0 ( ) ;
217
231
218
- if ( stream . _transformState . transforming )
232
+ if ( stream [ kTransformState ] . transforming )
219
233
throw new ERR_TRANSFORM_ALREADY_TRANSFORMING ( ) ;
220
234
return stream . push ( null ) ;
221
235
}
0 commit comments