Why not just iterate over the file object directly?