Skip to content

Instantly share code, notes, and snippets.

@flazz
Created December 9, 2010 22:54
Show Gist options
  • Select an option

  • Save flazz/735465 to your computer and use it in GitHub Desktop.

Select an option

Save flazz/735465 to your computer and use it in GitHub Desktop.
require 'digest/sha1'
def buf_sha file, buf_size
d = Digest::SHA1.new
buf = String.new
open(file) do |io|
d.update buf while io.read(buf_size, buf)
end
d
end
file = 'data'
MiB = 1024 ** 2
# uncomment the line below to generate the data file
# `dd if=/dev/urandom of=#{file} bs=#{MiB} count=550`
puts "Digest::SHA1#file:\t#{Digest::SHA1.file(file)}"
buf_size = 512 * MiB
puts "updated < 512 MiB:\t#{buf_sha(file, buf_size - 1)}"
puts "updated = 512 MiB:\t#{buf_sha(file, buf_size)}"
puts "updated = file size:\t#{buf_sha(file, File.size(file))}"
@flazz
Copy link
Author

flazz commented Sep 28, 2011 via email

@edsu
Copy link

edsu commented Sep 28, 2011

At any rate I've got a merge request for your bagit library which I think addresses large file support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment