portable encoding/decoding without going via a handle

Ganesh Sittampalam ganesh at earth.li
Tue Dec 11 01:56:10 CET 2012

On 28/11/2012 08:41, Judah Jacobson wrote:
> How about something like this?
> createFromHandle :: (Handle -> IO ()) -> IO ByteString

Of course, thanks!

I've knocked something up at http://hub.darcs.net/ganesh/bytestring-handle

The signatures are:

readHandle :: Bool -> BL.ByteString -> IO Handle
writeHandle :: Bool -> (Handle -> IO a) -> IO (BL.ByteString, a)

I went for lazy bytestrings as they fit my use case and mostly
generalise strict ones in this context - one exception is that writing
directly to a strict one could avoid a copy if you know the max size up

Comments etc welcome. I've written some tests but not very comprehensive
ones and I wouldn't be at all surprised if the seek behaviour is
completely broken.



More information about the Libraries mailing list