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



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/metamri/core_additions.rb', line 273

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