From: Robert Klemme Date: 2007-12-21T21:37:58+09:00 Subject: Re: Binary file reading in Ruby 2007/12/21, rohit2000s@yahoo.com : > Hi All, > > I am trying to read in a binary file of size 'n' using: > > mem_buf = IO.read(file_name, n, 0) > > Where file_name is an argument to the script. > > But after the read I observed that the size of the mem_buf is less > than 'n' (It should be equal to 'n'). > > (mem_buf.size != n). > > This script fails on the above read check. > > Any ideas what I might be doing wrong here. Any help will be > appreciated. Either, the file is smaller than n or you have an issue with conversion (typically on Windows). For binary files I'd do this which is more portable: mem_buf = File.open(file_name,"rb") {|io| io.read} Also, it helps documenting things. Bw, you do not need the offset and size arguments. Kind regards robert -- use.inject do |as, often| as.you_can - without end