| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- const crypto = require('crypto');
- const fs = require('fs');
- function md5File(path) {
- return new Promise((ok, ko) => {
- const readStream = fs.createReadStream(path);
- let hash = crypto.createHash('md5');
- readStream.on('data', chunk => hash.update(chunk.toString()));
- readStream.once('end', () => {
- ok(hash.digest('hex'));
- });
- readStream.once('error', () => ok(""));
- });
- }
- function md5String(input) {
- return crypto.createHash('md5').update(input).digest('hex');
- }
- function md5Stats(path) {
- return new Promise((ok, ko) => {
- fs.stat(path, (err, st) => {
- if (err)
- ok("");
- else
- ok(md5String(JSON.stringify({
- path: path,
- size: st.size,
- atimeMs: st.atimeMs,
- mtimeMs: st.mtimeMs,
- ctimeMs: st.ctimeMs
- })));
- });
- });
- }
- module.exports = {
- file: md5File,
- string: md5String,
- stats: md5Stats
- }
|