Created
July 21, 2015 17:24
-
-
Save snipsnipsnip/466d404b35b573f76e44 to your computer and use it in GitHub Desktop.
io_hasher.rb: digests an IO
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 'digest' | |
| class IOHasher | |
| def initialize(digest=Digest::MD5.new, buf='\0' * 4096) | |
| @digest = digest | |
| @buf = buf | |
| @chunk_size = buf.size | |
| end | |
| def hash_of(io) | |
| @buf.clear | |
| while io.read(@chunk_size, @buf) && [email protected]? | |
| @digest << @buf | |
| end | |
| @digest.digest! | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment