Rewrite read_file() to use a single static buffer.

This will reduce memory fragmentation, and also added a new test.