How do I convert Data.ByteString.Char8 to Data.ByteString.Lazy for use in Data.Binary.Get?

haskell

Solution

First of all, `Data.ByteString.Char8` is a module, not a type. Same with `Data.ByteString.Lazy`. That said, and assuming the obvious, then notice that `Data.ByteString.Char8.ByteString` is actually a re-export of `Data.ByteString.ByteString`. So all you need is the `fromStrict` function mentioned by Mikail Glushenkov.

Problem

I am in the midst of converting a package from using GHC.IO.Handle for networking to Network.Connection.Connection. One of the pain points is the number of places where Data.ByteString.Lazy.ByteString is being changed to Data.ByteString.Char8.ByteString. An example function is: ``` import qualified Data.ByteString.Lazy as BL -- gets the size of the frame -- the bytestring should be at least 7 bytes long, otherwise this method will fail peekFrameSize :: BL.ByteString -> PayloadSize peekFrameSize = runGet f where f = do void $ getWord8 -- 1 byte void $ (get :: Get ChannelID) -- 2 bytes get :: Get PayloadSize -- 4 bytes ``` How do I convert Data.ByteString.Char8.ByteString to Data.ByteString.Lazy.ByteString for use in Data.Binary.Get?

Original source