Created
December 30, 2014 09:16
-
-
Save sorrycc/04494c461c70159e1552 to your computer and use it in GitHub Desktop.
Compare sync pkg's md5.
This file contains hidden or 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
require('shelljs/global'); | |
var crypto = require('crypto'); | |
var stat = require('fs').statSync; | |
var join = require('path').join; | |
var dirname = require('path').dirname; | |
var readFile = require('fs').readFileSync; | |
var dir = join(__dirname, '../spmjs.io/data/repository'); | |
cd(dir); | |
find('./').forEach(function(file) { | |
if (!file.match(/\.tar\.gz$/)) return; | |
var absFile = join(dir, file); | |
var pkg = require(join(dirname(absFile), 'index.json')); | |
var filemd5 = md5file(absFile); | |
if (filemd5 !== pkg.md5) { | |
console.log('%s, file: %s, pkg: %s', file, filemd5, pkg.md5); | |
} | |
}); | |
function md5file(fpath) { | |
var md5 = crypto.createHash('md5'); | |
return md5.update(readFile(fpath)).digest('hex'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment