# Cgi.rb replacing "0x0a" symbols with "0x0d 0x0a"?

**URL:** <https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596>\
**Category:** ruby-talk\
**Created:** [6 September 2002 15:44 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596 "2002-09-06T15:44:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RayZ](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@RayZ](https://rubytalk.org/u/RayZ)\
**Post date:** [6 September 2002 15:44 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596/1 "2002-09-06T15:44:30Z")

</div>

Hi!  
I am new to ruby and lack of understanding  
– Ruby 1.6.7 & Apache 2.0.40 on win2k –

When i trying to make simple file-uploader i have been confront with a problem

[test.html]

> **···**
>
> * * *
> attach file: --------------
> ## then [test.rb]
> 
> #!/ruby/bin/ruby  
> require ‘cgi’  
> …  
> someFile, = cgi[‘attach\_file’]
> 
> data = someFile.read
> 
> ## newFile = File.new(CustomDir + newFilename + extension, “w”) newFile.write(data) newFile.close …
> 
> Binary file successfully written to the destination but replaced  
> "0x0a" symbols with “0x0d 0x0a” (’\r’-\>’\r\n’)
> 
> Please, can anyone explain me - what’s wrong?
> 
> P.S. sorry for my bad english. not expirienced yet 😉
> 
> * * *
> 
> Andrew “RayZ” V Rumm

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [6 September 2002 15:53 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596/2 "2002-09-06T15:53:48Z")

</div>

Well, I know nothing on win32 but try with "wb"

> newFile = File.new(CustomDir + newFilename + extension, "w")

&nbsp;&nbsp;&nbsp;newFile = File.new(CustomDir + newFilename + extension, "wb")

do say that you want a binary file (without conversion)

Guy Decoux

---

<div class="post-metadata">

**Author:** ![Christian\_Szegedy](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Christian\_Szegedy](https://rubytalk.org/u/Christian_Szegedy)\
**Post date:** [6 September 2002 16:11 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596/3 "2002-09-06T16:11:17Z")

</div>

RayZ wrote:

I am just guessing (I don’t use MSW), but you may try :

newFile = File.new(CustomDir + newFilename + extension, “wb”)

Note the “wb” open modifier (I would try “bw” also…)

Regards, Christian

---

<div class="post-metadata">

**Author:** ![RayZ](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@RayZ](https://rubytalk.org/u/RayZ)\
**Post date:** [6 September 2002 16:04 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596/4 "2002-09-06T16:04:11Z")

</div>

Thanx, Guy  
That’s it. It’s works fine with “wb”.

---

<div class="post-metadata">

**Author:** ![RayZ](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@RayZ](https://rubytalk.org/u/RayZ)\
**Post date:** [6 September 2002 17:44 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596/5 "2002-09-06T17:44:55Z")

</div>

> I am just guessing (I don’t use MSW), but you may try :  
> newFile = File.new(CustomDir + newFilename + extension, “wb”)  
> Note the “wb” open modifier (I would try “bw” also…)  
> Regards, Christian

oke, i am developing my web-server under Windows locally now, and in  
future i am planning to use the same ruby sources under Linux

will that “wb” open modifier works with Linux ?

Andrew Rumm.

---

<div class="post-metadata">

**Author:** ![Christian\_Szegedy](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@Christian\_Szegedy](https://rubytalk.org/u/Christian_Szegedy)\
**Post date:** [6 September 2002 18:11 UTC](https://rubytalk.org/t/cgi-rb-replacing-0x0a-symbols-with-0x0d-0x0a/1596/6 "2002-09-06T18:11:56Z")

</div>

RayZ wrote:

> oke, i am developing my web-server under Windows locally now, and in  
> future i am planning to use the same ruby sources under Linux
> 
> will that “wb” open modifier works with Linux ?
> 
> Andrew Rumm.

Yes.
