The following script takes a list of values, creates a table, and writes that table to file. Standard Lua file i/o in its default text mode and fhSaveTextFile(...) both do the correct translation to Windows text files, with each line terminating in <CR><LF>. However, createTextFile(...) writes a binary file, not text, with just a <LF> line ending. This is identical to the file created with Lua file i/o specifying a binary output.
IMO opinion, this is very confusing, and means that different techniques will be needed to read back a file created with fhFileUtils compared with other standard Windows text files. If I try to add the \r explicitly when creating the contents, createTextFile(...) ignores it anyway and still produces incorrect line endings.
Code: Select all
fhfu = require('fhFileUtils')
F1 = 'V:\\Junk\\JunkLuaText.txt'
F2 = 'V:\\Junk\\JunkLuaBin.txt'
F3 = 'V:\\Junk\\JunkFH.txt'
F4 = 'V:\\Junk\\JunkFHFU.txt'
tblT = {}
table.insert(tblT, 'line1')
table.insert(tblT, 'line2')
table.insert(tblT, 'line3')
filet = io.open(F1, 'w')
io.output(filet)
io.write(table.concat(tblT, '\n') .. '\n')
io.close()
fileb = io.open(F2, 'wb')
io.output(fileb)
io.write(table.concat(tblT, '\n') .. '\n')
io.close()
fhSaveTextFile(F3, table.concat(tblT, '\n') .. '\n')
fhfu.createTextFile(F4, true, true, table.concat(tblT, '\n') .. '\n', 8)