title: How to generalize reads from url and file in Haskell
body: <p>I develop an application that borrows data from the Internet by chunks with the given offset. For testing purposes I have a dump file that contains lines where each line corresponds to the separate chunk. I want to generalize read operations from url and dump file. Currently, I have the following functions:</p>
  
  <pre><code>getChunk :: DataSourceMode -&gt; Config -&gt; Int -&gt; Int -&gt; IO FetchResult
  getChunk DSNormal config ownerId' offset' = do ...
  getChunk DSFromFile config ownerId' offset' = do ...
  </code></pre>
  
  <p>The problem with the current implementation is that it reads dump file on each getChunk call and it's, obviously, ineffective. The first idea is to save the lines from the dump file into list, but then it wouldn't be easy to generalize it with readings from url. I suppose, conduits or pipes could be used to construct source of chunks, but I'm not familiar with these libraries; should I use one of them, or, maybe, there's a better solution?</p>