10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/shellfie/output_writer.rb', line 10
def write(path, extension:, io: nil)
FileUtils.mkdir_p(output_directory(path)) unless stdout?(path)
temp = Tempfile.new(["shellfie", ".#{extension}"], output_directory(path), binmode: true)
temp.close
yield temp.path
if stdout?(path)
return File.binread(temp.path) unless io
File.open(temp.path, "rb") { |source| IO.copy_stream(source, io) }
return path
end
FileUtils.mv(temp.path, path)
path
ensure
if temp
temp.close unless temp.closed?
File.delete(temp.path) if File.exist?(temp.path)
end
end
|