File tree 3 files changed +40
-1
lines changed
3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
var fs = require ( 'graceful-fs' ) ;
4
4
var stripBom = require ( 'strip-bom-stream' ) ;
5
+ var lazystream = require ( 'lazystream' ) ;
5
6
6
7
function streamFile ( file , opt , cb ) {
7
- file . contents = fs . createReadStream ( file . path ) ;
8
+ var filePath = file . path ;
9
+
10
+ file . contents = new lazystream . Readable ( function ( ) {
11
+ return fs . createReadStream ( filePath ) ;
12
+ } ) ;
8
13
9
14
if ( opt . stripBOM ) {
10
15
file . contents = file . contents . pipe ( stripBom ( ) ) ;
Original file line number Diff line number Diff line change 16
16
"graceful-fs" : " ^4.0.0" ,
17
17
"gulp-sourcemaps" : " ^1.5.2" ,
18
18
"is-valid-glob" : " ^0.3.0" ,
19
+ "lazystream" : " ^1.0.0" ,
19
20
"merge-stream" : " ^1.0.0" ,
20
21
"mkdirp" : " ^0.5.0" ,
21
22
"object-assign" : " ^4.0.0" ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ var should = require('should');
19
19
require ( 'mocha' ) ;
20
20
21
21
var wipeOut = function ( ) {
22
+ this . timeout ( 20000 ) ;
22
23
spies . setError ( 'false' ) ;
23
24
statSpy . reset ( ) ;
24
25
chmodSpy . reset ( ) ;
@@ -1366,4 +1367,36 @@ describe('dest stream', function() {
1366
1367
. once ( 'finish' , done ) ;
1367
1368
} ) ;
1368
1369
1370
+ it ( 'should not exhaust available file descriptors when streaming thousands of files' , function ( done ) {
1371
+ // This can be a very slow test on boxes with slow disk i/o
1372
+ this . timeout ( 0 ) ;
1373
+
1374
+ // Make a ton of hard links
1375
+ var numFiles = 6000 ;
1376
+ var srcFile = path . join ( __dirname , './fixtures/test.coffee' ) ;
1377
+ fs . mkdirSync ( path . join ( __dirname , './out-fixtures' ) ) ;
1378
+ fs . mkdirSync ( path . join ( __dirname , './out-fixtures/in/' ) ) ;
1379
+
1380
+ for ( var idx = 0 ; idx < numFiles ; idx ++ ) {
1381
+ fs . linkSync ( srcFile , path . join ( __dirname , './out-fixtures/in/test' + idx + '.coffee' ) ) ;
1382
+ }
1383
+
1384
+ var srcStream = vfs . src ( path . join ( __dirname , './out-fixtures/in/*.coffee' ) , { buffer : false } ) ;
1385
+ var destStream = vfs . dest ( './out-fixtures/out/' , { cwd : __dirname } ) ;
1386
+
1387
+ var fileCount = 0 ;
1388
+
1389
+ srcStream
1390
+ . pipe ( through . obj ( function ( file , enc , cb ) {
1391
+ fileCount ++ ;
1392
+
1393
+ cb ( null , file ) ;
1394
+ } ) )
1395
+ . pipe ( destStream )
1396
+ . once ( 'finish' , function ( ) {
1397
+ fileCount . should . equal ( numFiles ) ;
1398
+ done ( ) ;
1399
+ } ) ;
1400
+ } ) ;
1401
+
1369
1402
} ) ;
You can’t perform that action at this time.
0 commit comments