6464'use strict' ;
6565
6666const {
67+ ObjectDefineProperty,
6768 ObjectSetPrototypeOf,
69+ Symbol
6870} = primordials ;
6971
7072module . exports = Transform ;
@@ -75,12 +77,15 @@ const {
7577 ERR_TRANSFORM_WITH_LENGTH_0
7678} = require ( 'internal/errors' ) . codes ;
7779const Duplex = require ( '_stream_duplex' ) ;
80+ const internalUtil = require ( 'internal/util' ) ;
81+
7882ObjectSetPrototypeOf ( Transform . prototype , Duplex . prototype ) ;
7983ObjectSetPrototypeOf ( Transform , Duplex ) ;
8084
85+ const kTransformState = Symbol ( 'kTransformState' ) ;
8186
8287function 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+
150164Transform . 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
169183Transform . 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.
186200Transform . 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