Forum: Ruby Extra CR chars inserted into a downloaded file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A78c2495717d6738dd65000f7f97d3a1?d=identicon&s=25 Nate Morse (Guest)
on 2006-05-26 15:42
(Received via mailing list)
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") {|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
Fc784eadb3b54531fdc3d2053db6f83f?d=identicon&s=25 Mat Schaffer (Guest)
on 2006-05-26 16:08
(Received via mailing list)
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
A78c2495717d6738dd65000f7f97d3a1?d=identicon&s=25 Nate Morse (Guest)
on 2006-05-26 18:24
(Received via mailing list)
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
Fc784eadb3b54531fdc3d2053db6f83f?d=identicon&s=25 Mat Schaffer (Guest)
on 2006-05-26 19:02
(Received via mailing list)
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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-05-26 23:58
(Received via mailing list)
On May 26, 2006, at 9:39 AM, Nate Morse wrote:

> open("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", 'rb') { |f|
   ...etc...
}
This topic is locked and can not be replied to.