Created
April 10, 2017 22:55
-
-
Save rpearce/48db5e41d7dde123fc86b81b3437f064 to your computer and use it in GitHub Desktop.
Rails – open a file, read it and write it to a temp file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tmp | |
def self.build(src:, name:, ext:, binmode: false) | |
file = Tempfile.new([name, ext], Rails.root.join('tmp')) | |
file.binmode if binmode | |
open(src) { |f| file.write(f.read) } | |
file.rewind | |
file.close | |
file | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment