@@ -149,6 +149,70 @@ describe('fs.write()', () => {
149
149
} )
150
150
} )
151
151
152
+ describe ( 'fs.readv()' , ( ) => {
153
+ let TEST_FILE
154
+ let TEST_DATA
155
+ let TEST_FD
156
+
157
+ beforeEach ( ( ) => {
158
+ TEST_FILE = path . join ( os . tmpdir ( ) , 'fs-extra' , 'readv-test-file' )
159
+ TEST_DATA = crypto . randomBytes ( SIZE )
160
+ fs . writeFileSync ( TEST_FILE , TEST_DATA )
161
+ TEST_FD = fs . openSync ( TEST_FILE , 'r' )
162
+ } )
163
+
164
+ afterEach ( ( ) => {
165
+ return fs . close ( TEST_FD )
166
+ . then ( ( ) => fs . remove ( TEST_FILE ) )
167
+ } )
168
+
169
+ describe ( 'with promises' , ( ) => {
170
+ it ( 'returns an object' , ( ) => {
171
+ const bufferArray = [ Buffer . alloc ( SIZE / 2 ) , Buffer . alloc ( SIZE / 2 ) ]
172
+ return fs . readv ( TEST_FD , bufferArray , 0 )
173
+ . then ( ( { bytesRead, buffers } ) => {
174
+ assert . strictEqual ( bytesRead , SIZE , 'bytesRead is correct' )
175
+ assert . deepStrictEqual ( buffers , bufferArray , 'returned data matches mutated input param' )
176
+ assert . deepStrictEqual ( Buffer . concat ( buffers ) , TEST_DATA , 'data is correct' )
177
+ } )
178
+ } )
179
+
180
+ it ( 'returns an object when minimal arguments are passed' , ( ) => {
181
+ const bufferArray = [ Buffer . alloc ( SIZE / 2 ) , Buffer . alloc ( SIZE / 2 ) ]
182
+ return fs . readv ( TEST_FD , bufferArray )
183
+ . then ( ( { bytesRead, buffers } ) => {
184
+ assert . strictEqual ( bytesRead , SIZE , 'bytesRead is correct' )
185
+ assert . deepStrictEqual ( buffers , bufferArray , 'returned data matches mutated input param' )
186
+ assert . deepStrictEqual ( Buffer . concat ( buffers ) , TEST_DATA , 'data is correct' )
187
+ } )
188
+ } )
189
+ } )
190
+
191
+ describe ( 'with callbacks' , ( ) => {
192
+ it ( 'works' , done => {
193
+ const bufferArray = [ Buffer . alloc ( SIZE / 2 ) , Buffer . alloc ( SIZE / 2 ) ]
194
+ fs . readv ( TEST_FD , bufferArray , 0 , ( err , bytesRead , buffers ) => {
195
+ assert . ifError ( err )
196
+ assert . strictEqual ( bytesRead , SIZE , 'bytesRead is correct' )
197
+ assert . deepStrictEqual ( buffers , bufferArray , 'returned data matches mutated input param' )
198
+ assert . deepStrictEqual ( Buffer . concat ( buffers ) , TEST_DATA , 'data is correct' )
199
+ done ( )
200
+ } )
201
+ } )
202
+
203
+ it ( 'works when minimal arguments are passed' , done => {
204
+ const bufferArray = [ Buffer . alloc ( SIZE / 2 ) , Buffer . alloc ( SIZE / 2 ) ]
205
+ fs . readv ( TEST_FD , bufferArray , ( err , bytesRead , buffers ) => {
206
+ assert . ifError ( err )
207
+ assert . strictEqual ( bytesRead , SIZE , 'bytesRead is correct' )
208
+ assert . deepStrictEqual ( buffers , bufferArray , 'returned data matches mutated input param' )
209
+ assert . deepStrictEqual ( Buffer . concat ( buffers ) , TEST_DATA , 'data is correct' )
210
+ done ( )
211
+ } )
212
+ } )
213
+ } )
214
+ } )
215
+
152
216
describe ( 'fs.writev()' , ( ) => {
153
217
let TEST_FILE
154
218
let TEST_DATA
0 commit comments