From: Roger Pack on
Is there the possibility this would fail in 1.9?

big = eval(File.read("out_inspect.small"))
File.open("out.marshal", "w") do |f|

f.write(Marshal.dump(big))

end
Marshal.load(File.open('out.marshal', 'r'))


When I do this with large structures (on windows) I get messages like:

bad.rb:7:in `load': dump format error for symbol(0x6c) (ArgumentError)


irb(main):001:0> Encoding.default_external
=> #<Encoding:IBM437>
irb(main):002:0> Encoding.default_internal
=> nil

But I had assumed since I was reading and writing in the same mode it
would work all right. Was I wrong?
-r
--
Posted via http://www.ruby-forum.com/.

From: Rob Biedenharn on
On Jun 23, 2010, at 7:01 PM, Roger Pack wrote:

> Is there the possibility this would fail in 1.9?
>
> big = eval(File.read("out_inspect.small"))
> File.open("out.marshal", "w") do |f|
>
> f.write(Marshal.dump(big))
>
> end
> Marshal.load(File.open('out.marshal', 'r'))
>
>
> When I do this with large structures (on windows) I get messages like:
>
> bad.rb:7:in `load': dump format error for symbol(0x6c) (ArgumentError)
>
>
> irb(main):001:0> Encoding.default_external
> => #<Encoding:IBM437>
> irb(main):002:0> Encoding.default_internal
> => nil
>
> But I had assumed since I was reading and writing in the same mode it
> would work all right. Was I wrong?
> -r

You almost certainly want the 'rb' and 'wb' modes on Windows to read
and write in binary, rather than text, mode.

-Rob

Rob Biedenharn
http://agileconsultingllc.com
Rob(a)AgileConsultingLLC.com
http://gaslightsoftware.com
rab(a)GaslightSoftware.com



From: Roger Pack on

>> But I had assumed since I was reading and writing in the same mode it
>> would work all right. Was I wrong?
>> -r
>
> You almost certainly want the 'rb' and 'wb' modes on Windows to read
> and write in binary, rather than text, mode.

Hmm. The problem may occur when I read the file in--because I'm not
reading it in Binary mode, I'm actually reading it in as ascii + some
encoding (Encoding.default_external), which is IBM437

I'm still not entirely sure why something like this *shouldn't* round
trip appropriately though.

--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Roger Pack wrote:
>
>>> But I had assumed since I was reading and writing in the same mode it
>>> would work all right. Was I wrong?
>>> -r
>>
>> You almost certainly want the 'rb' and 'wb' modes on Windows to read
>> and write in binary, rather than text, mode.
>
> Hmm. The problem may occur when I read the file in--because I'm not
> reading it in Binary mode, I'm actually reading it in as ascii + some
> encoding (Encoding.default_external), which is IBM437
>
> I'm still not entirely sure why something like this *shouldn't* round
> trip appropriately though.

If you're under Windows, ruby/C will translate \r\n to \n on read and
vice versa on write, unless you open the file in binary mode.
--
Posted via http://www.ruby-forum.com/.

From: Roger Pack on

>> I'm still not entirely sure why something like this *shouldn't* round
>> trip appropriately though.
>
> If you're under Windows, ruby/C will translate \r\n to \n on read and
> vice versa on write, unless you open the file in binary mode.

Yes, but if I read and write both in ASCII mode, should it not be
expected to round trip? I'm a bit confused...

-r
--
Posted via http://www.ruby-forum.com/.