streaming-bytestring库在 打印大约 512 个字节后给出错误。
错误:
openBinaryFile: resource exhausted (Too many open files)
代码:
import Control.Monad.Trans (lift, MonadIO)
import Control.Monad.Trans.Resource (runResourceT, MonadResource, MonadUnliftIO, ResourceT, liftResourceT)
import qualified Data.ByteString.Streaming as BSS
import qualified Data.ByteString.Streaming.Char8 as BSSC
import System.TimeIt
main :: IO ()
main = timeIt $ runResourceT $ dump $ BSS.drop 24 $ BSS.readFile "filename"
dump :: MonadIO m => BSS.ByteString m r -> m ()
dump bs = do
isEmpty <- BSS.null_ bs
if isEmpty then return ()
else do
BSSC.putStr $ BSS.take 1 bs
dump $ BSS.drop 1 bs