Where is Network.Socket.ByteString.Lazy's sendTo?

a 夏天 提交于 2019-12-08 09:59:30

Note that sendTo is strict in the data sent, and so there's no real logic to passing it a lazy bytestring. That's why the function only exists on strict bytestrings.

The answer was to make a new function:

import Data.ByteString as BS
import Data.ByteString.Lazy as LBS

lazyToStrictBS :: LBS.ByteString -> BS.ByteString
lazyToStrictBS x = BS.concat $ LBS.toChunks x

and use it to convert the Lazy.ByteString into a normal ByteString.

Here's the converse, so that I find it when I google this problem again in future.

import Data.ByteString as BS
import Data.ByteString.Lazy as LBS

strictToLazyBS :: BS.ByteString -> LBS.ByteString
strictToLazyBS x = LBS.fromChunks [x] 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!