# Extra CR chars inserted into a downloaded file

**URL:** <https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721>\
**Category:** Ruby\
**Created:** [May 26, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721 "2006-05-26T15:42:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nate\_Morse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@Nate\_Morse](https://www.ruby-forum.com/u/Nate_Morse)\
**Post date:** [May 26, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721/1 "2006-05-26T15:42:34Z")

</div>

Hello all,  
Could anyone help shed light on some pesky (extra) Carrige Rreturns  
'\r’s

I’m in a windows environment, and I’m seeing extra chars in a download  
vs. direct file access.  
normally I would not care but later I will be checking MD5’s on both  
sides and they will not match.

# Ruby file downloadFile.rb

require ‘open-uri’

open(“[http://localhost/test/test.txt](http://localhost/test/test.txt)”) {|f|  
f.each\_line {|line| p line}  
p f.content\_type  
p f.charset + ‘\n’

}

File.open(“C:/www/test/test.txt”, “r”) {|f|  
f.each\_line {|line| p line}  
}

# EOF

→

> ruby downloadFile.rb  
> “abcdefg\r\n”  
> “abcdefg\r\n”  
> “abcdefg\r\n”  
> “text/plain”  
> “iso-8859-1”

“abcdefg\n”  
“abcdefg\n”  
“abcdefg\n”

> Exit code: 0

thanks,  
Nate Morse

---

<div class="post-metadata">

**Author:** ![Nate\_Morse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@Nate\_Morse](https://www.ruby-forum.com/u/Nate_Morse)\
**Post date:** [May 26, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721/2 "2006-05-26T16:08:04Z")

</div>

On May 26, 2006, at 9:39 AM, Nate Morse wrote:

> require ‘open-uri’  
> }  
> “iso-8859-1”
> 
> “abcdefg\n”  
> “abcdefg\n”  
> “abcdefg\n”
> 
> > Exit code: 0
> 
> thanks,  
> Nate Morse

I would blame the webserver before ruby… Try to make the webserver  
consider .txt to be binary data, and see what happens.  
-Mat

---

<div class="post-metadata">

**Author:** ![Nate\_Morse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@Nate\_Morse](https://www.ruby-forum.com/u/Nate_Morse)\
**Post date:** [May 26, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721/3 "2006-05-26T18:24:13Z")

</div>

Hi Mat et.al.  
Trying various Apache config settings such as:  
# tried others such as application/x-gzip and  
application/octet-stream …  
AddType application/x-other .txt

yeilds:  
p f.content\_type --\> ‘application/x-other’  
p f.charset --\> nil

but the extra \r’s are still appearing “abcdefg\r\n”,  
also I downloaded the same file using FireFox with no extra chars  
hmmm… do I dive into the source of Net::HTTP, or is the jury still  
out on Apache  
–Nate

---

<div class="post-metadata">

**Author:** ![Nate\_Morse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@Nate\_Morse](https://www.ruby-forum.com/u/Nate_Morse)\
**Post date:** [May 26, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721/4 "2006-05-26T23:58:45Z")

</div>

On May 26, 2006, at 9:39 AM, Nate Morse wrote:

> open(“[http://localhost/test/test.txt](http://localhost/test/test.txt)”) {|f|  
> f.each\_line {|line| p line}  
> p f.content\_type  
> p f.charset + ‘\n’
> 
> }

Have we tried:

open(“[http://localhost/test/test.txt](http://localhost/test/test.txt)”, ‘rb’) { |f|  
…etc…  
}

---

<div class="post-metadata">

**Author:** ![Nate\_Morse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7cd45c/32.png) [@Nate\_Morse](https://www.ruby-forum.com/u/Nate_Morse)\
**Post date:** [May 26, 2006, 7:02pm UTC](https://www.ruby-forum.com/t/extra-cr-chars-inserted-into-a-downloaded-file/61721/5 "2006-05-26T19:02:31Z")

</div>

I’d do one last thing. I seem to remember something about \r\n being  
the line separator for the HTTP standard (in the RFC). If you could  
hack together something that accesses apache without Net::HTTP, I’d  
try that. If it works, then the problem lies in Net:::HTTP.  
Good luck,  
Mat
