Browse files

; removal

  • Loading branch information...
1 parent efd8dbf commit 0413236c01f77e5f08e657822a365bb14ea02012 @serby committed Apr 21, 2013
Showing with 25 additions and 25 deletions.
  1. +25 −25 lib/map-path.js
View
50 lib/map-path.js
@@ -5,77 +5,77 @@ var url = require('url')
, path = require('path')
, _ = require('lodash')
, walker = require('walker')
-;
+
module.exports = function(dirPath, params, callback) {
var
files = []
if ((callback === undefined) && (typeof params === 'function')) {
- callback = params;
+ callback = params
}
var options = _.extend({
basePath: '',
hash: hash
- }, params);
+ }, params)
if (!dirPath) {
- return callback(new Error('Path is required'));
+ return callback(new Error('Path is required'))
}
function hash(filename, callback) {
var
md5sum = crypto.createHash('md5'),
- s = fs.ReadStream(filename);
+ s = fs.ReadStream(filename)
s.on('data', function(d) {
- md5sum.update(d);
- });
+ md5sum.update(d)
+ })
s.on('end', function() {
- callback(undefined, md5sum.digest('hex'));
- });
+ callback(undefined, md5sum.digest('hex'))
+ })
}
function makeHashMap (callback) {
- var hashMap = Object.create(null);
+ var hashMap = Object.create(null)
async.forEach(files, function(filename, fileCallback) {
hash(filename, function(error, fileHash) {
var
urlPath = path.normalize('/' + filename.substring(dirPath.length + 1)).replace(/\\/g, '/'),
- pos = urlPath.lastIndexOf('/');
+ pos = urlPath.lastIndexOf('/')
hashMap[urlPath] =
urlPath.substring(0, pos) + '/' + fileHash +
- urlPath.substring(pos) || url;
+ urlPath.substring(pos) || url
- fileCallback(error);
- });
+ fileCallback(error)
+ })
}, function(error) {
if (error) {
- return callback(error);
+ return callback(error)
}
- callback(undefined, hashMap);
- });
+ callback(undefined, hashMap)
+ })
}
if (options.fileList) {
for (var i in options.fileList) {
- files.push(options.fileList[i]);
+ files.push(options.fileList[i])
}
- makeHashMap(callback);
- return;
+ makeHashMap(callback)
+ return
}
- // else
walker(dirPath)
+
.on('file', function(filename) {
- files.push(filename);
+ files.push(filename)
})
.on('end', function() {
- makeHashMap(callback);
- });
-};
+ makeHashMap(callback)
+ })
+}

0 comments on commit 0413236

Please sign in to comment.