I have tried looking for best practices to convert a standard txt file to binary and am still not understanding it so well, and am wondering if someone can explain it a little better. So lets say I have my_file.txt and want to convert it to my_file.bin. What is the best practice at converting the whole file at once? Can I just write the whole file to a new .bin file? Or do I have to iterate through the file and convert line by line, etc?
I have tried things such as
old_text = File.open('my_file.txt').read
bin_file = File.new("my_file.bin","w+") # I understand w+ may not be the correct option
bin_file.puts(old_text)
bin_file.close
but when trying to read the bin_file nothing is returned. Is there a better practice to completing this?