From: Robert Klemme Date: 2009-11-29T21:10:11+09:00 Subject: Re: Ruby byte access to disk sectors like dd does On 29.11.2009 01:25, Gary Hasson wrote: > Thank you all for your guidance. I am now able to do with Ruby what I > previously need dd for. > > However, I am not able to cleanly test for the end of file due to the > following error: > > until file_1.eof? > file_1_byte = file_1.sysread( 1 ) > end > > ERROR MSG: > /Ruby_file_test.rb:23:in `sysread': sysread for buffered IO (IOError) > from ./Ruby_file_test.rb:23 > > All of my file accesses are sysread, syswrite, and sysseek, which are > not compatible with IO#eof. > > Using the file size to prevent hitting the EOF does not work for > /dev/sdb. > > So, I just let it generate an EOF error and then rescue it. > > It seems like there ought to be a working EOF function for IO#sys... Question is why do you use #sysread in the first place? As far as I can see there is no advantage of using #sysread here. Also, reading a single byte at a time might be easier for the implementation but it is almost inevitably dramatically slower than reading in chunks. *If* you use #sysread you should definitively read in chunks because #sysread does not buffer IIRC. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/