Created
July 24, 2014 21:45
-
-
Save calvinmetcalf/6559b3966a0cd8a2c217 to your computer and use it in GitHub Desktop.
browserify | node hasher.js './bundle.%s.js'
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
var fs = require('fs'); | |
var util = require("util"); | |
var crypto = require("crypto"); | |
var shasum = crypto.createHash('sha1'); | |
var tempName = './.temp' + Math.random(); | |
var temp = fs.createWriteStream(tempName); | |
process.stdin.pipe(shasum); | |
process.stdin.pipe(temp); | |
process.stdin.on('end', function() { | |
var name = util.format(process.argv[2],shasum.digest('hex').slice(0,7)); | |
fs.createReadStream(tempName).pipe(fs.createWriteStream(name)).on('end', function (){ | |
fs.unlink(temp, function (e) { | |
if (e) { | |
process.exit(1); | |
} | |
process.exit(); | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment