From: Bill Kelly Date: 2009-11-29T03:12:48+09:00 Subject: Re: Ruby byte access to disk sectors like dd does From: "Robert Klemme" > On 11/28/2009 01:26 AM, Bill Kelly wrote: >> >> :) Here's a stab at it... (it does work properly if the last >> read returns fewer than 16 bytes.) > > What makes it stop working properly if the file size is a multiple of 16? It works OK in either case, is what I was trying to say. :) >> ruby -e 'File.open("/dev/hdb", "rb") {|io| print(io.read(512))}' | >> ruby -e 'i=0; while(x=ARGF.read(16)); puts("%08x %-32s %s" % [i, x.unpack("H*"), x.tr("^\040-\176",".")]); i+=16; end' > > Why do you separate this in two processes? I've munged it a bit... Same reason dd and hexdump are separate programs. http://www.faqs.org/docs/artu/ch01s06.html > ruby -e 'File.open("/dev/hdb", "rb"){|io|i=0;while(l=io.read(16)); > printf("%06x %-32s %s\n",i,l.unpack("H*").first,l.tr("^\040-\176",".")); > i+=l.bytesize end}' > > > Cheers > > robert Regards, Bill