mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Reimplement hashFile locally
Replace the 10 MB of dependencies that is hash-files with a homebrew Promise based implementation of hashFile that uses crypto and fs. This somehow also ends up being the same amount of code as the one using hash-files.
This commit is contained in:
1 parent
0e849488e2
commit
13a069a798
3 files changed
+39
-38
No files matched your search
+22
@@ -0,0 +1,22 @@
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves to the SHA1 hash of the file given by path
|
||||
*/
|
||||
exports.hashFile = function(path) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let hasher = crypto.createHash('sha1')
|
||||
hasher.setEncoding('hex')
|
||||
hasher.on('finish', function() {
|
||||
resolve(hasher.read());
|
||||
});
|
||||
|
||||
let stream = fs.createReadStream(path);
|
||||
stream.on('error', function(error) {
|
||||
// the docs doesn't say anything about what's passed on error
|
||||
reject(error);
|
||||
});
|
||||
stream.pipe(hasher);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user