I have an wrapper class that has a method that goes off and downloads a file from a web server and needs to return said file. The HttpWebResponse object returns a Stream for the body.
Should I return a stream? Or should I convert it to a byte array and return that instead?
This wrapper class may be used in several places so I need a solid way to return the file. In every case, the file will be saved somewhere after receiving it from the adapter class.
Short answer: Yes, it’s fine.
Long answer: Yes, it’s completely safe to return a
Stream. The garbage collector is smart in .NET and you don’t have to worry about theStreambeing disposed of or anything. (That is, unless you callDispose()on it — which you should not if you are planning on reusing it.)