backport binwrite from Ruby 2.1+
This commit is contained in:
parent
8e96ce0aa5
commit
5af3d319d6
@ -93,12 +93,9 @@ class Pathname
|
|||||||
open("w", *open_args) { |f| f.write(content) }
|
open("w", *open_args) { |f| f.write(content) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Note: Ruby 2.1+ has Pathname#write and Pathname#binwrite
|
def binwrite(contents, *open_args)
|
||||||
def binwrite binary_content
|
open("wb", *open_args) { |f| f.write(contents) }
|
||||||
raise "Will not overwrite #{to_s}" if exist?
|
end unless method_defined?(:binwrite)
|
||||||
dirname.mkpath
|
|
||||||
File.open(self, 'wb') {|f| f.write binary_content }
|
|
||||||
end
|
|
||||||
|
|
||||||
# NOTE always overwrites
|
# NOTE always overwrites
|
||||||
def atomic_write content
|
def atomic_write content
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user