forked from jeerbl/webfonts-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
19 lines (17 loc) · 763 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var crypto = require('crypto');
var fs = require('fs');
module.exports = {
hashFiles: function (files, hashLength) {
// FIXME: For compatibility with the hash-files package, this
// function just sorts by filename and hashes the concatenation of
// the file contents. This algorithm will not detect certain
// changes where files are renamed or chunks are moved across
// file boundaries (https://github.com/mac-/hash-files/issues/4).
hashLength = hashLength && +hashLength >= 8 && +hashLength <= 32 ? +hashLength : 20;
var hash = crypto.createHash('sha1');
Array.from(new Set(files)).sort().forEach(function (file) {
hash.update(fs.readFileSync(file));
});
return hash.digest('hex').slice(0, hashLength);
}
};