forked from gulpjs/gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate readDir, avoid fs.stat() in two places
- Loading branch information
Showing
5 changed files
with
44 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
var fs = require('fs'); | ||
|
||
module.exports = function (file, cb) { | ||
fs.stat(file.path, function (err, stat) { | ||
if (stat.isDirectory()) { | ||
file.isDirectory = true; | ||
return cb(null, file); | ||
} | ||
fs.readFile(file.path, function (err, data) { | ||
if (err) return cb(err); | ||
file.contents = data; | ||
cb(null, file); | ||
}); | ||
fs.readFile(file.path, function (err, data) { | ||
if (err) return cb(err); | ||
file.contents = data; | ||
cb(null, file); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var es = require('event-stream'); | ||
var fs = require('fs'); | ||
|
||
var readDir = require('./readDir'); | ||
var bufferFile = require('./bufferFile'); | ||
var streamFile = require('./streamFile'); | ||
|
||
module.exports = function(opt) { | ||
return es.map(function (file, cb) { | ||
|
||
// don't read anything - just pass names | ||
if (!opt.read) { | ||
return cb(null, file); | ||
} | ||
|
||
fs.stat(file.path, function (err, stat) { | ||
|
||
// don't fail to read a directory | ||
if (stat.isDirectory()) { | ||
return readDir(file, cb); | ||
} | ||
|
||
// read and pass full contents | ||
if (opt.buffer) { | ||
return bufferFile(file, cb); | ||
} | ||
|
||
// dont buffer anything - just pass streams | ||
return streamFile(file, cb); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function (file, cb) { | ||
file.isDirectory = true; | ||
cb(null, file); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
var fs = require('fs'); | ||
|
||
module.exports = function (file, cb) { | ||
fs.stat(file.path, function (err, stat) { | ||
if (stat.isDirectory()) { | ||
file.isDirectory = true; | ||
return cb(null, file); | ||
} | ||
file.contents = fs.createReadStream(file.path); | ||
cb(null, file); | ||
}); | ||
file.contents = fs.createReadStream(file.path); | ||
cb(null, file); | ||
}; |