Module: SamplingHash
- Defined in:
- lib/sampling-hash.rb,
lib/sampling-hash/hash.rb,
lib/sampling-hash/sampler.rb,
lib/sampling-hash/version.rb,
lib/sampling-hash/sampling-io.rb
Defined Under Namespace
Classes: Hash, Sampler, SamplingIO
Constant Summary collapse
- VERSION =
'0.0.2'
Class Method Summary collapse
Class Method Details
.hash(path, seed = File.size(path)) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sampling-hash.rb', line 8 def self.hash(path, seed = File.size(path)) raise ArgumentError, 'file not found' unless File.file?(path) hash = XXhash::Internal::StreamingHash.new(seed) sio = SamplingIO.new(File.open(path, 'r')) sio.samples do |chunk| hash.update(chunk) end hash.digest end |