class Puppet::FileSystem::File19

Public Instance Methods

binread(path) click to toggle source
# File lib/puppet/file_system/file19.rb, line 2
def binread(path)
  path.binread
end
compare_stream(path, stream) click to toggle source

Provide an encoding agnostic version of #compare_stream

The FileUtils implementation in Ruby 2.0+ was modified in a manner where it cannot properly compare File and StringIO instances. To sidestep that issue this method reimplements the faster 2.0 version that will correctly compare binary File and StringIO streams.

# File lib/puppet/file_system/file19.rb, line 12
def compare_stream(path, stream)
  open(path, 0, 'rb') do |this|
    bsize = stream_blksize(this, stream)
    sa = "".force_encoding('ASCII-8BIT')
    sb = "".force_encoding('ASCII-8BIT')
    begin
      this.read(bsize, sa)
      stream.read(bsize, sb)
      return true if sa.empty? && sb.empty?
    end while sa == sb
    false
  end
end