Hi,
I need decode a binary file, (small enough to fit in memory).
At the present I have code like this:
class Dotqread
def initialize(fn)
@blob = File.open(fn).read
end
def wordread
a = @blob.unpack("s")[0]
@blob = @blob[2..-1]
a
end
def longread
a = @blob.unpack("L")[0]
@blob = @blob[4..-1]
a
end
def txtread
a = wordread
r = Opstring.new @blob[0...a]
@blob = @blob[a..-1] if a > 0
r
end
......
but as you can imagine performance is horrible.
What I seem to need is either:
string.unpack(format, offset) ## which I couldn.t find, but
should be easy to hack,
or:
iostream.unpack(format) ## not found either.
Is there another way to do what I want ? Did I miss some library ?
Cheers,
Han Holl