Sha256: 36b763e4b0c54aabbe7f539ac7dbbd1abf7be859e7ca090e2b04195084ccf9d3

Contents?: true

Size: 958 Bytes

Versions: 11

Compression:

Stored size: 958 Bytes

Contents

require 'digest/sha1'

module Ms
  class Msrun
    # the mzXML digest is from the start of the document to the end of the
    # first sha1 tag: '...<sha1>'
    module Sha1
      module_function

      # returns [calculated digest, recorded digest] for an mzXML file 
      def digest_mzxml_file(file)
        recorded_digest = nil

        incr_digest = ""
        #incr_digest = Digest::SHA1.new
        endpos = nil
        File.open(file, 'rb') do |io|
          while line = io.gets
            if line.include?("<sha1>")  
              incr_digest << line[0, line.index("<sha1>") + 6]
              if line =~ %r{<sha1>(.*)</sha1>}
                recorded_digest = $1.dup
                break
              else
                incr_digest << line
              end
            end
          end
        end

        [Digest::SHA1.hexdigest(incr_digest), recorded_digest]
        #[incr_digest.hexdigest, recorded_digest]
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ms-msrun-0.3.6 lib/ms/msrun/sha1.rb
ms-msrun-0.3.5 lib/ms/msrun/sha1.rb
ms-msrun-0.3.4 lib/ms/msrun/sha1.rb
ms-msrun-0.3.3 lib/ms/msrun/sha1.rb
ms-msrun-0.3.2 lib/ms/msrun/sha1.rb
ms-msrun-0.3.1 lib/ms/msrun/sha1.rb
ms-msrun-0.3.0 lib/ms/msrun/sha1.rb
ms-msrun-0.2.4 lib/ms/msrun/sha1.rb
ms-msrun-0.2.1 lib/ms/msrun/sha1.rb
ms-msrun-0.2.0 lib/ms/msrun/sha1.rb
ms-msrun-0.1.0 lib/ms/msrun/sha1.rb