Robert Klemme
2/28/2008 8:55:00 AM
2008/2/28, Ben Aroia <benaroia@gmail.com>:
> The java background is killing me here. ;) Thanks for pointing out the
> IO#pos.
IMHO something else is killing you: you did give only fractions of
your problem description making it hard for people to come up with
suggestions.
Back to your problem: here's a more efficient solution than looping:
def read_hex_io(io, offset, count)
io.seek offset, File::SEEK_SET
bytes = io.read count
bytes.unpack("H*").shift
end
def read_hex(file, offset, count)
File.open(file, "rb") do |io|
read_hex_io io, offset, count
end
end
Note: use the block form of File.open to ensure timely and safe
closing of file descriptors.
Cheers
robert
--
use.inject do |as, often| as.you_can - without end