From: Ralph Mason Date: 2002-06-18T16:23:44+09:00 Subject: File Write bug - Ruby mswin I have an application that generated a binary file. It has always worked fine, however having recently switched to the mswin version of ruby I find that the application nolonger works correctly. The problem is that file.write (or file.print) is printing an extra byte! (sometimes) Note : ruby 1.6.6 (2001-12-26) [i586-mswin32] Example the code I run is zones.each{ |i| #write zones s = i.binstr(p) puts "Prewritten line = #{a} pos = #{file.pos} s size = #{s.size}" if a > 35 and a < 45 file.write s puts "PostWrite line = #{a} pos = #{file.pos} s size = #{s.size} " if a > 35 and a < 45 a+=1 p += i.poi_size() } here we just go through a collection writing each member to a file. Each member is 21 bytes. Here is the trace from the function Prewritten line = 39 pos = 843 s size = 21 PostWrite line = 39 pos = 864 s size = 21 Prewritten line = 40 pos = 864 s size = 21 PostWrite line = 40 pos = 885 s size = 21 Prewritten line = 41 pos = 885 s size = 21 PostWrite line = 41 pos = 907 s size = 21 Prewritten line = 42 pos = 907 s size = 21 PostWrite line = 42 pos = 928 s size = 21 Prewritten line = 43 pos = 928 s size = 21 PostWrite line = 43 pos = 949 s size = 21 You see that in line 41, the file offset is at 885 it writes 21 bytes and the fileoffset goes to 907 - (22 bytes on!) The trace running on ruby 1.6.5 (2001-09-19) [i386-cygwin] is Prewritten line = 39 pos = 843 s size = 21 PostWrite line = 39 pos = 864 s size = 21 Prewritten line = 40 pos = 864 s size = 21 PostWrite line = 40 pos = 885 s size = 21 Prewritten line = 41 pos = 885 s size = 21 PostWrite line = 41 pos = 906 s size = 21 Prewritten line = 42 pos = 906 s size = 21 PostWrite line = 42 pos = 927 s size = 21 Prewritten line = 43 pos = 927 s size = 21 PostWrite line = 43 pos = 948 s size = 21 You can see that the byte error does not occur. Does anyone have any idea what is going on with this? This seems like a pretty fundamental problem. Thanks Ralph