-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from andersk/hash-files
Remove hash-files dependency
- Loading branch information
Showing
3 changed files
with
24 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,19 @@ | ||
var hashFiles = require('hash-files'); | ||
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; | ||
return hashFiles.sync({ files: files }).slice(0, hashLength); | ||
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); | ||
} | ||
}; |