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
2010-03-17 03:28:37
That's the opposite of what I need!
jes5199
2010-03-17 04:33:14
Sorry misread you question. Take a look at http://tinyurl.com/ydrq8o8 seems to have streaming options.
nightshade427
2010-03-17 15:49:12
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
2010-03-17 16:53:33