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



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/metamri/core_additions.rb', line 250

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