EasyHttp / EasyHttp

Http Library for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decouple file-access logic

opened this issue · comments

Hello there,
I wanted to implement a simple progress-tracking and noticed that the logic to read the file, and write it to the request-stream is implemented several times, slightly differently, violating e.g. DRY or SoC.

  1. In the MultiPartStreamer class (here)
  2. In the HttpRequest class (here).

If you agree that this is a problem, how would you solve it?
My proposals:

  • A) Defining an interface like IFileDataProvider with a simple signature like WriteFileToStream(string path, Stream requestStream)
  • B) A parameter like Action<string, Stream, long> streamWriter

I see the following advantages of this approach:

  • Removes redundancy
  • Ensures SoC
  • Great flexibility: You don`t care if the file to upload is on your local computer, or a remote http resource