Changed filename parameter name, improved compatibility with StringIO as buffer
Unittests cover StringIO buffers and real files