refactored readLoop
This commit is contained in:
parent
440aee7536
commit
61fca70a5e
|
@ -40,6 +40,7 @@ module Network.Gemini.Capsule.Internal (
|
||||||
stripCRLF
|
stripCRLF
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Control.Monad (when)
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
import Control.Monad.Trans.Maybe (MaybeT (..))
|
import Control.Monad.Trans.Maybe (MaybeT (..))
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
|
@ -119,9 +120,10 @@ readLoop :: Int -> S.InputStream BS.ByteString -> MaybeT IO Builder
|
||||||
readLoop maxLen src =
|
readLoop maxLen src =
|
||||||
lift (S.read src) >>= \case
|
lift (S.read src) >>= \case
|
||||||
Nothing -> return mempty
|
Nothing -> return mempty
|
||||||
Just bs -> let len = BS.length bs in
|
Just bs -> do
|
||||||
if len > maxLen
|
let len = BS.length bs
|
||||||
then MaybeT $ return Nothing
|
when (len > maxLen) $
|
||||||
else (byteString bs <>) <$> readLoop (maxLen - len) src
|
MaybeT $ return Nothing
|
||||||
|
(byteString bs <>) <$> readLoop (maxLen - len) src
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user