Method: External::Io#copy

Defined in:
lib/external/io.rb

#copy(mode = "r", range = 0..length) ⇒ Object

– it appears that as long as the io opening t.path closes, the tempfile will be deleted at the exit of the ruby instance… otherwise it WILL NOT BE DELETED Make note of this in the documentation to be sure to close files if you start inserting because it may make tempfiles ++



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/external/io.rb', line 95

def copy(mode="r", range=0..length)
  self.flush
  
  temp = Tempfile.new("copy")
  temp.extend Io
  temp.insert(self, range)
  temp.close

  cp = File.open(temp.path, mode)
  cp.extend Io

  if block_given?
    begin
      yield(cp)
    ensure
      cp.close unless cp.closed?
      FileUtils.rm(cp.path) if File.exists?(cp.path)
    end
  else
    cp
  end
end