Because of a problem that manifested itself when running Madeleine on
Windows machines, we have discovered the following:

File.open("test.dat", "w") {|file|
  Marshal.dump("\r\n", file)
}
File.open("test.dat", "r") {|file|
  file.eof
  Marshal.load(file)
}

ArgumentError: marshal data too short

Note that if you remove the line file.eof, the program works without
error.
If you open the file "rb" (setting it to binmode) the program works
without error.
If you add file.rewind after file.eof, the program works without
error.

Note that Marshal.dump and Marshal.load both change the IO Stream to
binary mode internally;
Ruby source marshal.c:
	if (rb_respond_to(port, s_binmode)) {
	    rb_funcall2(port, s_binmode, 0, 0);
	}

The conclusion is that an IO stream cannot sucessfully be changed to
binary mode after it has been tested for EOF (unless reset first with
rewind).

Is this expected behaviour?

(Ruby 1.8.1)

Stephen Sykes

(Credit also to Martin Tampe for work on this problem)

+- S.D.Sykes - www.stephensykes.com -+
ruby -e '_=2;"||_25~!A59(1A~47!K~#-6<.A~".scan(/./){
putc$&>$`?$/:_+=$&[0]-?4}'