Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

.NET question about working with Streams

Back to Forum: Tech Off
  • User profile image
    stevo_

    Well, its more of a 'political' question about Streams, given a method that its main goal is to save streams to files, imagine this is perhaps a simple file manager.

    Provided with a stream, should this method set the position of the stream to 0 before writing? given that the majority of the time if the stream isn't at 0, the file will turn out corrupted.

    Or should it be expected that all callee's of the method ensures their stream is rewound before calling to save it?

    Edit: my current solution to this is to have overloads as such:

    DoThing(Stream stream)
    {
    DoThing(stream, true);
    }

    DoThing(Stream stream, bool rewindStream)
    {
    }

  • User profile image
    Sven Groot

    I'd have the caller worry about stream position (especially since not all streams are seekable).

  • User profile image
    stevo_

    Great point, keeps my methods signature cleaner that way also.

    I had originally thought the rewind overload was a little odd because it was at a different 'technical abstraction' from what the other parameters are (a bit like asking for someones name, date of birth and then the atomic mass of the average european grape).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.