[Win32utils-devel] win32-file: nread and nwrite

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Tue Nov 16 11:54:42 EST 2004


Hi all,

I've got alpha versions of nread and nwrite now added to the win32-file
class in CVS.  They seem to work fine, although I've noticed one bug in
the File#read method.  Let's say we have a text file with "hello world"
in it.  If I call nread with no arguments, it works fine:

fh = File.nopen("C:\\test.txt")
p fh.nread -> "hello world"
fh.close

But, if I try to specify an argument, it seems to always want to return
9 to 11 bytes for some reason:

fh = File.nopen("C:\\test.txt")
p fh.nread(5) -> "hello\001u\002\003\000\002"
fh.close

How is it picking up these extra bytes?

Let's modify test.txt to add the strings "this is a test" and "1 2 3" on
their own lines.  Now, if we modify our code again to read, say, 15
bytes, it works fine:

fh = File.nopen("C:\\test.txt")
p fh.nread(15) -> "hello world\r\nth"
fh.close

So, that works as expected.  Why is it acting weird with strings under
12 bytes?

Dan



More information about the win32utils-devel mailing list