O'Reilly logo

Text Processing with Ruby by Rob Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading Fixed-Width Files

Another way of processing files without consuming them whole is to consume a fixed number of bytes. It’s much like the streaming examples that we’ve seen, where we read from the file until we encountered a newline or until we encountered a comma. But instead of reading until we hit a particular character, we read, say, ten bytes from the current position, receiving a string containing those ten bytes.

This might seem an inflexible and impractical way of doing things. After all, how can we know at how many bytes from the start of the file we’ll find the information we want? But this sort of processing has several real-world applications and has an important performance characteristic that gives it many of the benefits ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required