@@ -126,13 +126,6 @@ class SubProcess extends EventEmitter {
126
126
// actually spawn the subproc
127
127
this . proc = spawn ( this . cmd , this . args , this . opts ) ;
128
128
129
- if ( this . proc . stdout ) {
130
- this . proc . stdout . setEncoding ( this . opts . encoding || 'utf8' ) ;
131
- }
132
- if ( this . proc . stderr ) {
133
- this . proc . stderr . setEncoding ( this . opts . encoding || 'utf8' ) ;
134
- }
135
-
136
129
// this function handles output that we collect from the subproc
137
130
/**
138
131
*
@@ -184,13 +177,20 @@ class SubProcess extends EventEmitter {
184
177
} ) ;
185
178
} ;
186
179
180
+ const isBuffer = Boolean ( this . opts . isBuffer ) ;
181
+ const encoding = this . opts . encoding || 'utf8' ;
182
+
187
183
if ( this . proc . stdout ) {
188
- this . proc . stdout . on ( 'data' , ( chunk ) => handleOutput ( { stdout : chunk . toString ( ) , stderr : '' } ) ) ;
184
+ this . proc . stdout . on ( 'data' , ( chunk ) =>
185
+ handleOutput ( { stdout : isBuffer ? chunk : chunk . toString ( encoding ) , stderr : '' } ) ,
186
+ ) ;
189
187
handleStreamLines ( 'stdout' , this . proc . stdout ) ;
190
188
}
191
189
192
190
if ( this . proc . stderr ) {
193
- this . proc . stderr . on ( 'data' , ( chunk ) => handleOutput ( { stdout : '' , stderr : chunk . toString ( ) } ) ) ;
191
+ this . proc . stderr . on ( 'data' , ( chunk ) =>
192
+ handleOutput ( { stdout : '' , stderr : isBuffer ? chunk : chunk . toString ( encoding ) } ) ,
193
+ ) ;
194
194
handleStreamLines ( 'stderr' , this . proc . stderr ) ;
195
195
}
196
196
0 commit comments