Hi all,<br><br>I've recently came across a problem when processing a large text file (around 2G in size).<br><br>I wrote a Haskell program to count the number of lines in the file.<br><br><br>module Main where<br><br>import System<br>
import qualified Data.ByteString.Char8 as S<br>-- import Prelude as S<br><br>main :: IO ()<br>main = do { args <- getArgs<br> ; case args of<br> { [ filename ] -> <br> do { content <- S.readFile filename<br>
; let lns = S.lines content<br> ; putStrLn (show $ length lns)<br> }<br> ; _ -> error "Usage : Wc <file>"<br> }<br>
}<br> <br><br>I get this error, if I use the ByteString module,<br>./Wc a.out<br>Wc: {handle: a.out}: hGetBuf: invalid argument (illegal buffer size (-1909953139))<br>Otherwise, it returns me the result.<br>
<br>Another observation is that if I reduce the size of the file, the ByteString version works too.<br><br>Is it a known limitation?<br><br>Regards,<br>Kenny<br><br><br>A generator program that generate large file. (Warning, it is very slow, I don't know how to speed it up)<br>
<br>-- generate a file<br><br>module Main where<br><br>import System<br>import qualified Data.ByteString.Char8 as S<br><br><br>l :: S.ByteString<br>l = S.pack "All work, no fun, make Kenny a dull boy. "<br><br>main :: IO ()<br>
main = do { args <- getArgs<br> ; case args of<br> { [ n, fn ] -> do { let i = read n<br> ; mapM_ (\s -> S.appendFile fn s) (take i $ repeat l) <br> }<br>
; _ -> return () <br> }<br> }<br><br><br><br>