Could I return a FileStream as a generic interface to a file?

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2010-05-04T18:29:08Z Indexed on 2010/05/04 18:38 UTC
Read the original article Hit count: 190

Filed under:
|
|
|

I'm writing a class interface that needs to return references to binary files. Typically I would provide a reference to a file as a file path. However, I'm considering storing some of the files (such as a small thumbnail) in a database directly rather then on a file system. In this case I don't want to add the extra step of reading the thumbnail out of the database onto the disc and then returning a path to the file for my program to read. I'd want to stream the image directly out of the database into my program and avoid writing anything to the disc unless the user explicit wants to save something.

Would having my interface return a FileStreamor even a Imagemake sense? Then it would be up to the implementing class to determine if the source of the FileStream or Image is a file on a disc or binary data in a database.

public interface MyInterface
{ 
    string Thumbnail {get;}
    string Attachment {get;}
}

vs

public interface MyInterface
{ 
    Image Thumbnail {get;}
    FileStream Attachment {get;}
}

© Stack Overflow or respective owner

Related posts about interface

Related posts about file-io