Project

General

Profile

Actions

Bug #13959

closed

IO.write(filename, Marshal.dump(obj), :encoding => 'binary') != File.open(filename, 'wb') { |fil| Marshal.dump(obj, fil) }

Added by fitmap (Justin Peal) over 6 years ago. Updated over 6 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x64-mingw32]
[ruby-core:83072]

Description

For some complex objects,

IO.write(filename, Marshal.dump(obj), :encoding => 'binary') and File.open(filename, 'wb') { |fil| Marshal.dump(obj, fil) }

can create different file content, and these files can't load each other by

Marshal.load(IO.read(filename, :encoding => 'binary')) and File.open(filename, 'rb') { |fil| return Marshal.load(fil) }

Detail is in the attached.


Files

test.rb (3.13 KB) test.rb Source file fitmap (Justin Peal), 10/01/2017 05:29 AM
test.txt (1.91 KB) test.txt Test result fitmap (Justin Peal), 10/01/2017 05:31 AM

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Rejected

:encoding => 'binary' does not set binmode, but just makes the result encoding ASCII-8bit.
Use IO.binread and IO.binwrite to read/write binary data.

Actions

Also available in: Atom PDF

Like0
Like0