If a function takes as an input the name of a text file, I can refactor it to instead take a file object (I call it "stream"; is there a better word?). The advantages are obvious - a function that takes a stream as an argument is:
- much easier to write a unit test for, since I don't need to create a temporary file just for the test
- more flexible, since I can use it in situations where I somehow already have the contents of the file in a variable
Are there any disadvantages to streams? Or should I always refactor a function from a file name argument to a stream argument (assuming, of course, the file is text-only)?