From: Park Heesob Date: 2007-10-26T00:03:44+09:00 Subject: Re: read write integer in binary into a file Hi, ----- Original Message ----- From: "Vianney Lecroart" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Thursday, October 25, 2007 11:36 PM Subject: read write integer in binary into a file > Hello, > > I have some big files with lot of "unsigned int" (4 bytes) numbers and I > want to read and write on these files. > > Currently, I found this to write: > > myfile << [mynum].pack("i") > > and to read: > > mynum = myfile.read(4).unpack("i").first > > I wonder if there's not something faster/simpler to do that without the > need to convert the number into an array into a string to finally > serialize it. > > Thank you. How about Marshal? myfile << Marshal.dump(mynum) and mynum = Marshal.load(myfile.read) Regards, Park Heesob