From: Peter Bailey Date: 2005-08-06T00:41:12+09:00 Subject: Re: Newbie - Help with using puts to binary file Thanks for your super quick response Austin, I'll give that a try! Austin Ziegler wrote: > On 8/5/05, Peter Bailey wrote: > >>I am writing a templating system to replace tags and values in template >>files. I am quite new to Ruby and am not sure I am going about things >>correctly. My prog runs great on text files, rtf, etc., but I am running >>into problems outputting to binary formats (e.g. word - sigh). My program >>just reads the whole file into a string, works on that, and then I >>output to another file using puts. This causes grief for word or open >>office etc when it tries to open the newly created file. >> >>I tried a simple test just reading in the file and writing it out, and I >>see that the puts adds 1 byte to the eof, a LF (working on OS X). I got >>the impression from reading docs that the puts would not mess with my >>ouput, but that is obviously not the case, as my simple test has shown. >> >>So, can anyone point me to a better way to write out the binary data so >>that it is not altered (except by me on purpose). I looked at the data >>input into a string, and it is correct. It is the output that is >>breaking things. >> >>Any help/pointers to explanations of how puts really works etc. or >>better alternatives much appreciated. > > > #puts will add an LF if it isn't present at the end of the output. > #print will not and #write will not. When I'm writing binary data, I > tend to use IO#write. > > -austin