How to preserve line endings in Ruby on Windows? -


i running ruby 1.9.3 on windows. when run following snippet of code

text = file.read(path) file.write(path, text) 

i exact same file when file has cr+lf line endings. when run on file lf line endings, changes cr+lf line endings.

how can read , write file using ruby on windows such line endings preserved, whether cr+lf or lf?

ruby, along perl , python, aware of os code running on, , automatically set line-endings should be.

if read, write, text file, settings kick in, , you'll see file change are.

if need have file unchanged, add b flag open statement, like:

file.open('path', 'wb') |fo|   fo.write(text) end 

for more information, see "io open mode".


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -