R
RNicz
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)
---
77c77
< @tmpfile = File.open(@tmpname, 'r+')
---
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
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.
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)
---
File::RDWR|File::CREAT|File::EXCL|File::BINARY, 0600)@tmpfile = File.open(tmpname,
77c77
< @tmpfile = File.open(@tmpname, 'r+')
---
---end---@tmpfile = File.open(@tmpname, 'rb+')
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
---end---alias_methodrg_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_methodrg_kind_of?, :kind_of?
def kind_of?(some_class)
org_kind_of?(some_class) || @_dc_obj.kind_of?(some_class)
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.