1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
2
+ const common = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
4
5
- var path = require ( 'path' ) ;
6
- var fs = require ( 'fs' ) ;
7
- var fn = path . join ( common . fixturesDir , 'elipses.txt' ) ;
8
- var rangeFile = path . join ( common . fixturesDir , 'x.txt' ) ;
5
+ const path = require ( 'path' ) ;
6
+ const fs = require ( 'fs' ) ;
7
+ const fn = path . join ( common . fixturesDir , 'elipses.txt' ) ;
8
+ const rangeFile = path . join ( common . fixturesDir , 'x.txt' ) ;
9
9
10
- var callbacks = { open : 0 , end : 0 , close : 0 } ;
10
+ const callbacks = { open : 0 , end : 0 , close : 0 } ;
11
11
12
- var paused = false ;
12
+ let paused = false ;
13
13
14
- var file = fs . ReadStream ( fn ) ;
14
+ const file = fs . ReadStream ( fn ) ;
15
15
16
16
file . on ( 'open' , function ( fd ) {
17
17
file . length = 0 ;
18
18
callbacks . open ++ ;
19
- assert . equal ( 'number' , typeof fd ) ;
19
+ assert . strictEqual ( typeof fd , 'number' ) ;
20
20
assert . ok ( file . readable ) ;
21
21
22
22
// GH-535
@@ -48,19 +48,17 @@ file.on('end', function(chunk) {
48
48
49
49
file . on ( 'close' , function ( ) {
50
50
callbacks . close ++ ;
51
-
52
- //assert.equal(fs.readFileSync(fn), fileContent);
53
51
} ) ;
54
52
55
- var file3 = fs . createReadStream ( fn , Object . create ( { encoding : 'utf8' } ) ) ;
53
+ const file3 = fs . createReadStream ( fn , Object . create ( { encoding : 'utf8' } ) ) ;
56
54
file3 . length = 0 ;
57
55
file3 . on ( 'data' , function ( data ) {
58
- assert . equal ( 'string' , typeof data ) ;
56
+ assert . strictEqual ( typeof data , 'string' ) ;
59
57
file3 . length += data . length ;
60
58
61
- for ( var i = 0 ; i < data . length ; i ++ ) {
59
+ for ( let i = 0 ; i < data . length ; i ++ ) {
62
60
// http://www.fileformat.info/info/unicode/char/2026/index.htm
63
- assert . equal ( '\u2026' , data [ i ] ) ;
61
+ assert . strictEqual ( data [ i ] , '\u2026' ) ;
64
62
}
65
63
} ) ;
66
64
@@ -69,74 +67,74 @@ file3.on('close', function() {
69
67
} ) ;
70
68
71
69
process . on ( 'exit' , function ( ) {
72
- assert . equal ( 1 , callbacks . open ) ;
73
- assert . equal ( 1 , callbacks . end ) ;
74
- assert . equal ( 2 , callbacks . close ) ;
75
- assert . equal ( 30000 , file . length ) ;
76
- assert . equal ( 10000 , file3 . length ) ;
70
+ assert . strictEqual ( callbacks . open , 1 ) ;
71
+ assert . strictEqual ( callbacks . end , 1 ) ;
72
+ assert . strictEqual ( callbacks . close , 2 ) ;
73
+ assert . strictEqual ( file . length , 30000 ) ;
74
+ assert . strictEqual ( file3 . length , 10000 ) ;
77
75
console . error ( 'ok' ) ;
78
76
} ) ;
79
77
80
- var file4 = fs . createReadStream ( rangeFile , Object . create ( { bufferSize : 1 ,
81
- start : 1 , end : 2 } ) ) ;
82
- assert . equal ( file4 . start , 1 ) ;
83
- assert . equal ( file4 . end , 2 ) ;
84
- var contentRead = '' ;
78
+ const file4 = fs . createReadStream ( rangeFile , Object . create ( { bufferSize : 1 ,
79
+ start : 1 , end : 2 } ) ) ;
80
+ assert . strictEqual ( file4 . start , 1 ) ;
81
+ assert . strictEqual ( file4 . end , 2 ) ;
82
+ let contentRead = '' ;
85
83
file4 . on ( 'data' , function ( data ) {
86
84
contentRead += data . toString ( 'utf-8' ) ;
87
85
} ) ;
88
86
file4 . on ( 'end' , function ( data ) {
89
- assert . equal ( contentRead , 'yz' ) ;
87
+ assert . strictEqual ( contentRead , 'yz' ) ;
90
88
} ) ;
91
89
92
- var file5 = fs . createReadStream ( rangeFile , Object . create ( { bufferSize : 1 ,
93
- start : 1 } ) ) ;
94
- assert . equal ( file5 . start , 1 ) ;
90
+ const file5 = fs . createReadStream ( rangeFile , Object . create ( { bufferSize : 1 ,
91
+ start : 1 } ) ) ;
92
+ assert . strictEqual ( file5 . start , 1 ) ;
95
93
file5 . data = '' ;
96
94
file5 . on ( 'data' , function ( data ) {
97
95
file5 . data += data . toString ( 'utf-8' ) ;
98
96
} ) ;
99
97
file5 . on ( 'end' , function ( ) {
100
- assert . equal ( file5 . data , 'yz\n' ) ;
98
+ assert . strictEqual ( file5 . data , 'yz\n' ) ;
101
99
} ) ;
102
100
103
101
// https://github.com/joyent/node/issues/2320
104
- var file6 = fs . createReadStream ( rangeFile , Object . create ( { bufferSize : 1.23 ,
105
- start : 1 } ) ) ;
106
- assert . equal ( file6 . start , 1 ) ;
102
+ const file6 = fs . createReadStream ( rangeFile , Object . create ( { bufferSize : 1.23 ,
103
+ start : 1 } ) ) ;
104
+ assert . strictEqual ( file6 . start , 1 ) ;
107
105
file6 . data = '' ;
108
106
file6 . on ( 'data' , function ( data ) {
109
107
file6 . data += data . toString ( 'utf-8' ) ;
110
108
} ) ;
111
109
file6 . on ( 'end' , function ( ) {
112
- assert . equal ( file6 . data , 'yz\n' ) ;
110
+ assert . strictEqual ( file6 . data , 'yz\n' ) ;
113
111
} ) ;
114
112
115
113
assert . throws ( function ( ) {
116
114
fs . createReadStream ( rangeFile , Object . create ( { start : 10 , end : 2 } ) ) ;
117
115
} , / " s t a r t " o p t i o n m u s t b e < = " e n d " o p t i o n / ) ;
118
116
119
- var stream = fs . createReadStream ( rangeFile , Object . create ( { start : 0 ,
120
- end : 0 } ) ) ;
121
- assert . equal ( stream . start , 0 ) ;
122
- assert . equal ( stream . end , 0 ) ;
117
+ const stream = fs . createReadStream ( rangeFile , Object . create ( { start : 0 ,
118
+ end : 0 } ) ) ;
119
+ assert . strictEqual ( stream . start , 0 ) ;
120
+ assert . strictEqual ( stream . end , 0 ) ;
123
121
stream . data = '' ;
124
122
125
123
stream . on ( 'data' , function ( chunk ) {
126
124
stream . data += chunk ;
127
125
} ) ;
128
126
129
127
stream . on ( 'end' , function ( ) {
130
- assert . equal ( 'x' , stream . data ) ;
128
+ assert . strictEqual ( stream . data , 'x' ) ;
131
129
} ) ;
132
130
133
131
// pause and then resume immediately.
134
- var pauseRes = fs . createReadStream ( rangeFile ) ;
132
+ const pauseRes = fs . createReadStream ( rangeFile ) ;
135
133
pauseRes . pause ( ) ;
136
134
pauseRes . resume ( ) ;
137
135
138
- var file7 = fs . createReadStream ( rangeFile , Object . create ( { autoClose : false } ) ) ;
139
- assert . equal ( file7 . autoClose , false ) ;
136
+ let file7 = fs . createReadStream ( rangeFile , Object . create ( { autoClose : false } ) ) ;
137
+ assert . strictEqual ( file7 . autoClose , false ) ;
140
138
file7 . on ( 'data' , function ( ) { } ) ;
141
139
file7 . on ( 'end' , function ( ) {
142
140
process . nextTick ( function ( ) {
@@ -154,18 +152,18 @@ function file7Next() {
154
152
file7 . data += data ;
155
153
} ) ;
156
154
file7 . on ( 'end' , function ( err ) {
157
- assert . equal ( file7 . data , 'xyz\n' ) ;
155
+ assert . strictEqual ( file7 . data , 'xyz\n' ) ;
158
156
} ) ;
159
157
}
160
158
161
159
// Just to make sure autoClose won't close the stream because of error.
162
- var file8 = fs . createReadStream ( null , Object . create ( { fd : 13337 ,
163
- autoClose : false } ) ) ;
160
+ const file8 = fs . createReadStream ( null , Object . create ( { fd : 13337 ,
161
+ autoClose : false } ) ) ;
164
162
file8 . on ( 'data' , function ( ) { } ) ;
165
163
file8 . on ( 'error' , common . mustCall ( function ( ) { } ) ) ;
166
164
167
165
// Make sure stream is destroyed when file does not exist.
168
- var file9 = fs . createReadStream ( '/path/to/file/that/does/not/exist' ) ;
166
+ const file9 = fs . createReadStream ( '/path/to/file/that/does/not/exist' ) ;
169
167
file9 . on ( 'data' , function ( ) { } ) ;
170
168
file9 . on ( 'error' , common . mustCall ( function ( ) { } ) ) ;
171
169
0 commit comments