[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Working with Tempfile class

rnicz

2/27/2005 1:35:00 AM

I've encountered following problems working with Tempfile:

1. Tempfile is not useful for working with binary data on Windows - I
guess that this is a problem specific only to native Windows platform.
The reason for this is that the underlying file is opened and reopened
without explicitly specified binary mode - so in Windows it is opened in
TEXT mode. That way binary data undergo newline translation and get
corrupted. Here is diff for tempfile.rb with proper patch. I'm not sure
if it is enough - it works for me.

---start---
55c55
< @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
---
> @tmpfile = File.open(tmpname,
File::RDWR|File::CREAT|File::EXCL|File::BINARY, 0600)
77c77
< @tmpfile = File.open(@tmpname, 'r+')
---
> @tmpfile = File.open(@tmpname, 'rb+')
---end---


2. Tempfile is not recognized as File - although it is File - isn't it?
I think that proper place to resolve this problem is delegate.rb file:

---start---
61a62,65
> alias_method :org_kind_of?, :kind_of?
> def kind_of?(some_class)
> org_kind_of?(some_class) || @_dc_obj.kind_of?(some_class)
> end
137a142,147
> end
> klass.module_eval do
> alias_method :org_kind_of?, :kind_of?
> def kind_of?(some_class)
> org_kind_of?(some_class) || @_dc_obj.kind_of?(some_class)
> end
---end---

This path changes kind_of? behavior so that it compares passed class not
only to itself but also to class of basic object. I didn't find tests
which could ensure me that these changes wouldn't break anything, so I
submit them under your careful consideration.

--
Best regards
RNicz


7 Answers

Tobias Peters

2/27/2005 2:27:00 AM

0

RNicz wrote:
> I've encountered following problems working with Tempfile:
>
> 1. Tempfile is not useful for working with binary data on Windows

Tempfile#binmode should solve that problem.

Tobias

Austin Ziegler

2/27/2005 3:28:00 PM

0

On Sun, 27 Feb 2005 10:34:56 +0900, RNicz <rnicz@fibernet.pl> wrote:
> 2. Tempfile is not recognized as File - although it is File - isn't it?
> I think that proper place to resolve this problem is delegate.rb file:

If your code is looking for #kind_of?(File) or #kind_of?(IO), it
shouldn't. It won't recognise custom "writeable" or "readable"
objects, e.g., StringIO or even strings that have had a custom #write
or #read method added.

-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca


rnicz

2/27/2005 8:00:00 PM

0

If only there was IO#binmode=...

Binary mode can be set only when opening file. IO#binmode reports IO
stream status.

irb(main):001:0> f=File.new('test', 'w')
=> #<File:test>
irb(main):002:0> f.binmode=true
NoMethodError: undefined method `binmode=' for #<File:test>
from (irb):2

Tobias Peters wrote:
> > 1. Tempfile is not useful for working with binary data on Windows
>
> Tempfile#binmode should solve that problem.


I forgot to mention that I use ruby 1.8.2 i386-mswin32 (One-Click
Installer, v. 1.8.2-14 Final)

--
Best regards
RNicz

rnicz

2/27/2005 9:54:00 PM

0

Oops, it realy works. I'm sorry that I have not checked this well
before posting.
--
RNicz

Andrzej Jarzabek

5/4/2013 6:35:00 PM

0

On 03/05/2013 21:31, Wojciech Mu?a wrote:
> On Thursday, May 2, 2013 4:40:00 PM UTC+2, M.M. wrote:
>> Co w og?le my?licie o frameworkach C++ do aplikacji webowych?
>
> ?e maj? bardzo ma?e szanse na rozw?j i szersze zastosowanie.
> Tak samo istniej? frameworki w Adzie, Haskellu i s?dz?, ?e
> wielu innych ma?o rozpowszechnionych j?zykach.

C++ jest chyba troch?bardziej rozpowszechniony?

wojtek.mula

5/4/2013 7:16:00 PM

0

On Saturday, May 4, 2013 8:34:47 PM UTC+2, Andrzej Jarzabek wrote:
> > Ze maja bardzo male szanse na rozwój i szersze zastosowanie.
> > Tak samo istnieja frameworki w Adzie, Haskellu i sadze, ze
> > wielu innych malo rozpowszechnionych jezykach.
>
> C++ jest chyba troche bardziej rozpowszechniony?

Oczywiscie. Moja wypowiedz byla nieprecyzyjna.

w.

Mariusz Marszalkowski

5/5/2013 9:59:00 PM

0

W dniu piatek, 3 maja 2013 22:45:35 UTC+2 uzytkownik A. L. napisal:
> On Fri, 3 May 2013 13:31:23 -0700 (PDT), Wojciech Mudz?a
> >Cadz?y myk polega na tym, dz?e te wszystkie dla php/ruby/pythona
> >sdz? na rynku od dawna, majdz? masdz? gotowcdz?w, materiadz?dz?w do nauki
> >i wystarczajdz? w 99% przypadkdz?w.
>
> ... i nie przekracaja mozliwosci intelektualnych przecietnego
> programisty..

Za to z narzedziami moze byc odwrotnie, a na pewno w moim przypadku
jest odwrotnie. Dokumentacje frameworkow do C++ w miare przyswajam, a z
takim django czy zendem mam problemy. Moze chodzi o to, ze WinAPI czy QT
ma bardzo dobra dokumentacje.

Pozdrawiam