From: GSP Date: 2001-07-13T04:13:48+09:00 Subject: [ruby-talk:17743] Re: Funky file.each_byte What you're running into, I think, is the fact that newlines in ms-dos are actually two characters (ascii 10 and 13, I think). When you're reading your file, the file system read's 10 and 13 and gives you one byte "\n". I tried a quick test using your code temp.txt = " 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 " with 6 newlines. The output: c:/temp.txt had 66 bytes via .each_byte, while file.stat.size reports 72 bytes. = 6 bytes difference. As Park Hee-Sob mentioned, reading in binary (f.binmode) format ignores this and gives you the exact number of bytes in the file. GSP "Tyler" wrote in message news:65d29696.0107111312.4a1e488d@posting.google.com... > Howdy! I was filtering some files and ran into an anomaly. > I'm running Ruby 1.6.4 on an old Windows machine. Everything > was fine when I was manipulating bytes with getc/putc, but that > seemed too C-ish, so I tried a tweak to a Ruby idiom. Imagine > my surprise and delight to discover that a file with some bytes > deleted was larger than the original file! Ditto for reading. > > count = 0 > f = File.new( ARGV[0], "r") > f.each_byte do > count += 1 > end > f.close > > printf( "%s had %d bytes via .each_byte,\n", ARGV[0], count) > printf( "while file.stat.size reports %d bytes.\n", File.stat(ARGV[0]).size) > > generates the following results: > > H:\ruby >ruby fsize.rb 1MEG.1 > 1MEG.1 had 1048553 bytes via .each_byte, > while file.stat.size reports 1048576 bytes. > > Any ideas? Is this a Windows-specific oddity or showing up elsewhere? > > TIA, Tyler >