@@ -37,6 +37,19 @@ function allocNewPool(poolSize) {
37
37
pool . used = 0 ;
38
38
}
39
39
40
+ // Check the `this.start` and `this.end` of stream.
41
+ function checkPosition ( pos , name ) {
42
+ if ( ! Number . isSafeInteger ( pos ) ) {
43
+ validateNumber ( pos , name ) ;
44
+ if ( ! Number . isInteger ( pos ) )
45
+ throw new ERR_OUT_OF_RANGE ( name , 'an integer' , pos ) ;
46
+ throw new ERR_OUT_OF_RANGE ( name , '>= 0 and <= 2 ** 53 - 1' , pos ) ;
47
+ }
48
+ if ( pos < 0 ) {
49
+ throw new ERR_OUT_OF_RANGE ( name , '>= 0 and <= 2 ** 53 - 1' , pos ) ;
50
+ }
51
+ }
52
+
40
53
function ReadStream ( path , options ) {
41
54
if ( ! ( this instanceof ReadStream ) )
42
55
return new ReadStream ( path , options ) ;
@@ -65,41 +78,15 @@ function ReadStream(path, options) {
65
78
this . closed = false ;
66
79
67
80
if ( this . start !== undefined ) {
68
- if ( ! Number . isSafeInteger ( this . start ) ) {
69
- validateNumber ( this . start , 'start' ) ;
70
- if ( ! Number . isInteger ( this . start ) )
71
- throw new ERR_OUT_OF_RANGE ( 'start' , 'an integer' , this . start ) ;
72
- throw new ERR_OUT_OF_RANGE (
73
- 'start' ,
74
- '>= 0 and <= 2 ** 53 - 1' ,
75
- this . start
76
- ) ;
77
- }
78
- if ( this . start < 0 ) {
79
- throw new ERR_OUT_OF_RANGE (
80
- 'start' ,
81
- '>= 0 and <= 2 ** 53 - 1' ,
82
- this . start
83
- ) ;
84
- }
81
+ checkPosition ( this . start , 'start' ) ;
85
82
86
83
this . pos = this . start ;
87
84
}
88
85
89
86
if ( this . end === undefined ) {
90
87
this . end = Infinity ;
91
88
} else if ( this . end !== Infinity ) {
92
- if ( ! Number . isSafeInteger ( this . end ) ) {
93
- if ( typeof this . end !== 'number' )
94
- throw new ERR_INVALID_ARG_TYPE ( 'end' , 'number' , this . end ) ;
95
- if ( ! Number . isInteger ( this . end ) )
96
- throw new ERR_OUT_OF_RANGE ( 'end' , 'an integer' , this . end ) ;
97
- throw new ERR_OUT_OF_RANGE ( 'end' , '>= 0 and <= 2 ** 53 - 1' , this . end ) ;
98
- }
99
-
100
- if ( this . end < 0 ) {
101
- throw new ERR_OUT_OF_RANGE ( 'end' , '>= 0 and <= 2 ** 53 - 1' , this . end ) ;
102
- }
89
+ checkPosition ( this . end , 'end' ) ;
103
90
104
91
if ( this . start !== undefined && this . start > this . end ) {
105
92
throw new ERR_OUT_OF_RANGE (
0 commit comments