write_binary(path, data)
public
Safely write a file in binary mode on all platforms.
Show source
def self.write_binary(path, data)
open(path, 'wb') do |io|
begin
io.flock(File::LOCK_EX)
rescue *WRITE_BINARY_ERRORS
end
io.write data
end
rescue Errno::ENOLCK
if Thread.main != Thread.current
raise
else
open(path, 'wb') do |io|
io.write data
end
end
end