@@ -17,7 +17,10 @@ const {
17
17
ERR_METHOD_NOT_IMPLEMENTED ,
18
18
} = require ( 'internal/errors' ) . codes ;
19
19
const { deprecate } = require ( 'internal/util' ) ;
20
- const { validateInteger } = require ( 'internal/validators' ) ;
20
+ const {
21
+ validateFunction,
22
+ validateInteger,
23
+ } = require ( 'internal/validators' ) ;
21
24
const { errorOrDestroy } = require ( 'internal/streams/destroy' ) ;
22
25
const fs = require ( 'fs' ) ;
23
26
const { kRef, kUnref, FileHandle } = require ( 'internal/fs/promises' ) ;
@@ -155,20 +158,9 @@ function ReadStream(path, options) {
155
158
156
159
this [ kFs ] = options . fs || fs ;
157
160
158
- if ( typeof this [ kFs ] . open !== 'function' ) {
159
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.open' , 'function' ,
160
- this [ kFs ] . open ) ;
161
- }
162
-
163
- if ( typeof this [ kFs ] . read !== 'function' ) {
164
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.read' , 'function' ,
165
- this [ kFs ] . read ) ;
166
- }
167
-
168
- if ( typeof this [ kFs ] . close !== 'function' ) {
169
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.close' , 'function' ,
170
- this [ kFs ] . close ) ;
171
- }
161
+ validateFunction ( this [ kFs ] . open , 'options.fs.open' ) ;
162
+ validateFunction ( this [ kFs ] . read , 'options.fs.read' ) ;
163
+ validateFunction ( this [ kFs ] . close , 'options.fs.close' ) ;
172
164
173
165
options . autoDestroy = options . autoClose === undefined ?
174
166
true : options . autoClose ;
@@ -310,30 +302,23 @@ function WriteStream(path, options) {
310
302
options . decodeStrings = true ;
311
303
312
304
this [ kFs ] = options . fs || fs ;
313
- if ( typeof this [ kFs ] . open !== 'function' ) {
314
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.open' , 'function' ,
315
- this [ kFs ] . open ) ;
316
- }
305
+
306
+ validateFunction ( this [ kFs ] . open , 'options.fs.open' ) ;
317
307
318
308
if ( ! this [ kFs ] . write && ! this [ kFs ] . writev ) {
319
309
throw new ERR_INVALID_ARG_TYPE ( 'options.fs.write' , 'function' ,
320
310
this [ kFs ] . write ) ;
321
311
}
322
312
323
- if ( this [ kFs ] . write && typeof this [ kFs ] . write !== 'function' ) {
324
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.write' , 'function' ,
325
- this [ kFs ] . write ) ;
313
+ if ( this [ kFs ] . write ) {
314
+ validateFunction ( this [ kFs ] . write , 'options.fs.write' ) ;
326
315
}
327
316
328
- if ( this [ kFs ] . writev && typeof this [ kFs ] . writev !== 'function' ) {
329
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.writev' , 'function' ,
330
- this [ kFs ] . writev ) ;
317
+ if ( this [ kFs ] . writev ) {
318
+ validateFunction ( this [ kFs ] . writev , 'options.fs.writev' ) ;
331
319
}
332
320
333
- if ( typeof this [ kFs ] . close !== 'function' ) {
334
- throw new ERR_INVALID_ARG_TYPE ( 'options.fs.close' , 'function' ,
335
- this [ kFs ] . close ) ;
336
- }
321
+ validateFunction ( this [ kFs ] . close , 'options.fs.close' ) ;
337
322
338
323
// It's enough to override either, in which case only one will be used.
339
324
if ( ! this [ kFs ] . write ) {
0 commit comments