tags:

views:

33

answers:

2

I've got a parser written using ruby's standard StringScanner. It would be nice if I could use it on streaming files. Is there an equivalent to StringScanner that doesn't require me to load the whole string into memory?

A: 

There is StringIO.

Sorry misread you question. Take a look at http://tinyurl.com/ydrq8o8 seems to have streaming options

nightshade427
That's the opposite of what I need!
jes5199
Sorry misread you question. Take a look at http://tinyurl.com/ydrq8o8 seems to have streaming options.
nightshade427
A: 

You might have to rework your parser a bit, but you can feed lines from a file to a scanner like this:

File.open('filepath.txt', 'r') do |file|
  scanner = StringScanner.new(file.readline)
  until file.eof?
    scanner.scan(/whatever/)
    scanner << file.readline
  end
end
mckeed