File.open(filename, 'rb:BINARY) { |f| f.read } might help not sure though. You can also look into the unpack method of a string that is used for returning a bunch of different serialization formats. http://www.ruby-doc.org/core/classes/String.html#M000760
--- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Thu, Oct 22, 2009 at 11:12 PM, Håkon Clausen <hako...@hclausen.net>wrote: > Hello, > > I'm struggling with converting a byte array into a ruby binary string. > Does anybody know how to make something like this pass? > > require 'test/unit' > include System::IO > class Binstring < Test::Unit::TestCase > > def test_binstring_bytea > fileName = 'flowers.jpg' > > #Ruby way > data1 = File.read(fileName) > > #.Net > fs = FileStream.new(fileName, FileMode.Open, FileAccess.Read); > br = BinaryReader.new(fs); > numBytes = FileInfo.new(fileName).Length; > buff = br.ReadBytes(numBytes); > data2 = System::Text::ASCIIEncoding.new.GetString(buff).to_s > > assert data1 == data2 > end > > end > > Regards, > > Håkon > > > -- > Håkon Clausen > Nosyko AS > > "Nobody will ever need more than 640k RAM!" - Bill Gates, 1981. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core@rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >
_______________________________________________ Ironruby-core mailing list Ironruby-core@rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core