Sha256: 057371f868754fc120c1d71e93eaafab7331ea543aa9863a143bfb57612ee0f8

Contents?: true

Size: 788 Bytes

Versions: 19

Compression:

Stored size: 788 Bytes

Contents

module AppleTvConverter
  module MovieHasher

    CHUNK_SIZE = 64 * 1024 # in bytes

    def self.compute_hash(filename)
      filesize = File.size(filename)
      hash = filesize

      # Read 64 kbytes, divide up into 64 bits and add each
      # to hash. Do for beginning and end of file.
      File.open(filename, 'rb') do |f|
        # Q = unsigned long long = 64 bit
        f.read(CHUNK_SIZE).unpack("Q*").each do |n|
          hash = hash + n & 0xffffffffffffffff # to remain as 64 bit number
        end

        f.seek([0, filesize - CHUNK_SIZE].max, IO::SEEK_SET)

        # And again for the end of the file
        f.read(CHUNK_SIZE).unpack("Q*").each do |n|
          hash = hash + n & 0xffffffffffffffff
        end
      end

      sprintf("%016x", hash)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
apple-tv-converter-0.7.4 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.7.3 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.7.2 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.7.1 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.7.0 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.6.2 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.6.0 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.9 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.8 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.7 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.6 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.5 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.4 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.3 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.2 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.5.1 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.4.4 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.4.3 lib/apple_tv_converter/movie_hasher.rb
apple-tv-converter-0.4.2 lib/apple_tv_converter/movie_hasher.rb