Issues with pack/write on WinXP compared to Linux

J

james.d.masters

I'm sure that this has to do with CR/LF on DOS/Windows filesystems,
but I'm not sure how to fix:

File.open('test', 'w') do |file|
file.write([10].pack('n')) #=> 2 [bytes]
end

On Linux, the file comes out as having 2 bytes (as expected):

% ls -l test
-rw-rw-r-- 1 jamesm eng 2 Mar 23 11:38 test
% od -h test
0000000 0a00
0000002

On WinXP it has 3 bytes (BTW, write still returns 2 [bytes] in irb on
WinXP):

bash-2.05a$ ls -l test
-rw-r--r-- 1 Administ None 3 Mar 23 11:40 test
bash-2.05a$ od -h test
0000000 0d00 000a
0000003

This does not happen when writing out another number (say 11). Again,
it's probably a CR/LF deal, but I don't know how to remedy. Thanks in
advance...
 
T

Tim Hunter

unknown said:
I'm sure that this has to do with CR/LF on DOS/Windows filesystems,
but I'm not sure how to fix:

File.open('test', 'w') do |file|
file.write([10].pack('n')) #=> 2 [bytes]
end

File.open('test', 'wb') do |file|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top