app/models/source.rb
def checksum
        digest = Digest::SHA256.new

        ::Zip::File.open(@file) do |zip_file|
          # Sort the entries by name to always digest in the same order
          zip_file.glob('*').sort_by(&:name).each do |entry|
            # We could read only the beginning of larger files
            raise 'File too large when extracted' if entry.size > MAX_SIZE

            # Digest the entry name
            digest.update entry.name

            # Digest the entry content
            buffer = ""
            io = entry.get_input_stream
            while io.read 16384, buffer
              digest.update buffer
            end
          end
        end

        digest.hexdigest
      end
# Digest entries name and content
# Don't use a Zip::InputStream to avoid difference with entry order change
Digest entries name and content
Don't use a Zip::InputStream to avoid difference with entry order change
Digest entries name and content Don ' t use a Zip :: InputStream to avoid difference with entry order change
def checksum
        digest = Digest::SHA256.new
        ::Zip::File.open(@file) do |zip_file|
          zip_file.glob('*').sort_by(&:name).each do |entry|
            raise 'File too large when extracted' if entry.size > MAX_SIZE
            digest.update entry.name
            buffer = ""
            io = entry.get_input_stream
            while io.read 16384, buffer
              digest.update buffer
            end
          end
        end
        digest.hexdigest
      end
def checksum digest = Digest :: SHA256 . new :: Zip :: File . open ( @file ) do | zip_file | zip_file . glob ( '*' ) . sort_by ( & :name ) . each do | entry | raise 'File too large when extracted' if entry . size > MAX_SIZE digest . update entry . name buffer = "" io = entry . get_input_stream while io . read 16384 , buffer digest . update buffer end end end digest . hexdigest end
Digest entries name and content
Don't use a Zip::InputStream to avoid difference with entry order change
Digest entries name and content Don ' t use a Zip :: InputStream to avoid difference with entry order change
# Sort the entries by name to always digest in the same order # We could read only the beginning of larger files # Digest the entry name # Digest the entry content