<commit_before>module Network.Wai.Handler.Helper
    ( requestBodyHandle
    , requestBodyFunc
    ) where

import System.IO (Handle)
import qualified Data.ByteString as B
import Data.ByteString.Lazy.Internal (defaultChunkSize)
import Network.Wai (Source (..))

requestBodyHandle :: Handle -> Int -> Source
requestBodyHandle h =
    requestBodyFunc go
  where
    go = Just `fmap` B.hGet h defaultChunkSize

requestBodyFunc :: IO (Maybe B.ByteString) -> Int -> Source
requestBodyFunc _ 0 = Source $ return Nothing
requestBodyFunc h len = Source $ do
    mbs <- h
    case mbs of
        Nothing -> return Nothing
        Just bs -> do
            let newLen = len - B.length bs
            return $ Just (bs, requestBodyFunc h $ max 0 newLen)<commit_msg>Fix hanging simpleserver<commit_after>module Network.Wai.Handler.Helper
    ( requestBodyHandle
    , requestBodyFunc
    ) where

import System.IO (Handle)
import qualified Data.ByteString as B
import Data.ByteString.Lazy.Internal (defaultChunkSize)
import Network.Wai (Source (..))

requestBodyHandle :: Handle -> Int -> Source
requestBodyHandle h =
    requestBodyFunc go
  where
    go i = Just `fmap` B.hGet h (min i defaultChunkSize)

requestBodyFunc :: (Int -> IO (Maybe B.ByteString)) -> Int -> Source
requestBodyFunc _ 0 = Source $ return Nothing
requestBodyFunc h len = Source $ do
    mbs <- h len
    case mbs of
        Nothing -> return Nothing
        Just bs -> do
            let newLen = len - B.length bs
            return $ Just (bs, requestBodyFunc h $ max 0 newLen)
{'fraction_non_alphanumeric': 0.08560311284046693, 'fraction_numerical': 0.0025940337224383916, 'mean_word_length': 2.916243654822335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1756157', 'n_tokens_mistral': 453, 'n_tokens_neox': 440, 'n_words': 154}