Closed milyord closed 10 years ago
Because it doesn't matter. It's unique enough for its purpose.
@sindresorhus do you have anything to back this up?
@matsko Maths.
8 hex characters means your rev prefix range is 0x00000000
through 0xffffffff
, or in other words, enough for 4,294,967,296 unique hash prefixes. MD5 is a good (checksum) hash, meaning it's very well distributed.
So the odds of you finding two (non-equal) files that have a hash collision are approximately 5.421e-20
, or 1 in 18,447,000,000,000,000,000.
… which is approximately the same as the odds of you buying two Powerball lotto tickets and winning the jackpot with both tickets.
Here is an argument from another angle: I like the look of a full hash. It makes things look so sophisticated! 8 characters seems so flimsy, even if the science says otherwise. Can we at least specify the cut length? (I would want at least 16 chars, if not the full hash)
Feel free to modify it, but we're not going to add options just because it looks better in your opinion. The more options the more useless things the user has to consider and care about. I prefer simple interfaces.
Is there a particular reason why the md5 hash is sliced? Why not use the entire hash?
https://github.com/sindresorhus/gulp-rev/blob/master/index.js#L39
Thanks.