I couldn't see any tests for this function. This is also another one that would benefit from receiving a file object to make it easier to test.