Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/metamri/core_additions.rb

Overview

Method from ftools - requiring fileutils instead for Ruby 1.9 compatibility and explicitly adding this single method.

Constant Summary collapse

BUFSIZE =
8 * 1024

Class Method Summary collapse

Class Method Details

.compare(from, to, verbose = false) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/metamri/core_additions.rb', line 181

def self.compare(from, to, verbose = false)
  $stderr.print from, " <=> ", to, "\n" if verbose

  return false if stat(from).size != stat(to).size

  from = open(from, "rb")
  to = open(to, "rb")

  ret = false
  fr = tr = ''

  begin
    while fr == tr
      fr = from.read(BUFSIZE)
      if fr
        tr = to.read(fr.size)
      else
        ret = to.read(BUFSIZE)
        ret = !ret || ret.length == 0
        break
      end
    end
  rescue
    ret = false
  ensure
    to.close
    from.close
  end
  ret
end