Method: Rozi.open_file
- Defined in:
- lib/rozi/module_functions.rb
.open_file(path, mode = "r") ⇒ File .open_file(path, mode = "r") {|file| ... } ⇒ void
Opens a file with the correct settings for usage with Ozi Explorer
The file instance has UTF-8 internal encoding and ISO-8859-1 external encoding. When writing, all line endings are converted to CRLF. When reading, all line endings are converted to LF.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rozi/module_functions.rb', line 24 def open_file(path, mode="r") file = File.open(path, mode) opts = {undef: :replace, replace: "?"} if mode.include? "w" opts[:crlf_newline] = true else opts[:universal_newline] = true end file.set_encoding("ISO-8859-1", "UTF-8", opts) if block_given? yield file file.close return nil else return file end end |