[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby binary temp file

wx

10/9/2007 5:56:00 PM

require 'tempfile'
f = Tempfile.open 'tmp'

will open f in text mode (mode = 'w', not 'wb'). Any non-hacky way to
open this in binary mode? I can, of course, make f, close it and open
it as a real file - it's just this is not atomic.

2 Answers

Daniel Berger

10/9/2007 6:47:00 PM

0



On Oct 9, 12:00 pm, wi...@yahoo.com wrote:
> require 'tempfile'
> f = Tempfile.open 'tmp'
>
> will open f in text mode (mode = 'w', not 'wb'). Any non-hacky way to
> open this in binary mode? I can, of course, make f, close it and open
> it as a real file - it's just this is not atomic.

Not that I can see.

May I suggest file-temp? It opens in binary mode by default:

http://raa.ruby-lang.org/project...

Regards,

Dan


James Gray

10/9/2007 6:56:00 PM

0

On Oct 9, 2007, at 1:00 PM, wimxa@yahoo.com wrote:

> require 'tempfile'
> f = Tempfile.open 'tmp'
>
> will open f in text mode (mode = 'w', not 'wb'). Any non-hacky way to
> open this in binary mode? I can, of course, make f, close it and open
> it as a real file - it's just this is not atomic.

You can switch it to binary mode after it's open:

#!/usr/bin/env ruby -wKU

require "tempfile"

f = Tempfile.new "binary"
f.binmode # switch to binary mode

__END__

James Edward Gray II