[web-devel] [ANNOUNCE] First release of crypto-conduit

Felipe Almeida Lessa felipe.lessa at gmail.com
Sun Jan 8 01:39:41 CET 2012


On Sat, Jan 7, 2012 at 10:04 PM, Grant <thelff at hotmail.com> wrote:
> Thanks for getting back to me so fast!  Actually, I need to include a string
> with the file length plus the file stream itself and THEN hash that whole thing
> together. The example below works, but the file is processed twice.
>
> Alternatively, I could create a specialised Source that gets the file size from
> the handle and then processes the file but that looks ugly. Any ideas?

I think we need the following:

  openFile :: ResourceIO m :: FilePath -> ResourceT m Handle
  sourceHandle :: ResourceIO m => Handle -> Source m B.ByteString

So you would do something like

  runResourceT $ do
    handle <- CB.openFile fp
    fileSize <- liftIO $ hFileSize handle
    let source = CL.sourceList [encodeFileSize fileSize]
                 `mappend` CB.sourceHandle handle
    source $$ sinkHash

Cheers!

-- 
Felipe.



More information about the web-devel mailing list